Hello, i want to simulate the river current by moving the player when it walks in toward the river flow, i guess i have to use just the collision component on river and not the rigidbody, so when the player collide with the river it start to be pushed by the flow of current. Is it right?
Another effect that would be nice it would be the swimming effect but totally unaware how to do it, any suggestion?
Hi @ayrin,
For the river current Iād say you can start simply by applying a constant force towards the direction of the water flow, while the player is in touch, and maybe at a certain depth/away from shore.
To keep him afloat and simulate buoyancy you could also apply a force equal and at the opposite direction of the gravity force, so the player floats on the water. Iād say thatās the start of having him swim.
Uhm instead of applying a force contrary to make it swim, couldnāt i change the weight value of the player to zero? It would be easiest.
Well you can do that, but it may break any other forces that you apply to your character. Since those forces were calculated with a given mass. But give it a try, it can be also a nice learning experience around physics.
Thatās true @Leonidas, but for movement i usually donāt use forces so it may work for swimming, canāt work if i want to apply both the zero weight and the river current. So i will be aware of that. Thanks.
This is a very bad practice. What you are essentially doing is telling āthe normal laws of physics donāt apply to this river.ā This leads to a huge number of potential of ābugsā that arenāt bugs, just the code doing its thing.
Say you make the player have a mass of 0, but now a block of 1 mass falls on their head, not from so far away. This block will completely sweep your player off its course, while the desired effect is of course for the block to bump off the players head. You canāt check for the block via the river, since the block comes in contact with the player first, so now you have to write some code on the river to make the player check for collisions and youāve tangled yourself up inside a tight knot indeed.
Iād strongly suggest taking Leonidasā advice. Buoyancy has been invented, a quick Google search should get you 90% there.
Thanks @CaseyDeCoder i see all your points, i will go check about buoyancy and take that route. Thanks for the advice.