Hey im working on a mini-golf game and want to fine tune the drag force so that when the ball reaches a certain speed it slows down until it completly stops and goes to sleep.
but i cant seem to figure out how to do that already tried physics materials both on the ball and the floor, timeline, finterp to. anyone has ideas ?
this gives you the linear velocity
you multiply by -1 like this
and you have the opposite velocity vector…you can then multiply the result by a factor (like .05) and add to current linear velocity (actually it will subtract because you reversed)
and remember also multiply by delta time and then assign the results again:
3 Likes
I would try two ways and see which works better:
- In Tick(): Get the velocity of the ball. Turn it into a unit direction vector and a magnitude. Subtract a constant times the delta-time from the magnitude. If it’s negative, set magnitude to 0. Set the velocity of the ball to (unit-direction-vector times new-magnitude.)
- Get velocity of ball. If the velocity is smaller than some epsilon, force the body to sleep. Else apply impulse of strength (constant times delta-time) in the opposite direction of the velocity.
Either one or both of these may work, you’ll want to try them to see. The good news with both of these is that they have a fixed deceleration (tuned by the constant.) Anything that uses the current velocity as a scaling factor, will work more like “air drag” and won’t actually ever get the velocity to zero, because the counter-force scales down as velocity scales down.
1 Like