How to simulate river current

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.

1 Like

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.

1 Like

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.

1 Like

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.

1 Like