How to code the force of a river current?

I have rivers in my game, but they’re only aesthetic.
What I’d like is for the river to have a current that can push any rigidbodies that collide with it.
Is there a way to do this?

The river is curvy and built from a spline, so I was initially Googling how to add force along a spline, but the solutions seemed only for moving a specific GameObject along a spline rather than a spline creating a general force that any rigidbody which crosses its path could be affected by.

Thanks for any and all suggestions, spline or not!

Get the direction vector of the spline in the point that is closest to the rigidbody and you have the direction of the force. Multiply it by some force intensity (i.e. a configurable parameter) and you have the force to apply to the rigidbody.

1 Like