# 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.

2 Likes

Thanks @CaseyDeCoder i see all your points, i will go check about buoyancy and take that route. Thanks for the advice.

1 Like