I’m trying to make a simple game where the player just launches a ball at targets, and I thought it would add some fun to the movement for the ball to hover and push away from the nearest objects. I have this working, however the ball predictably doesn’t exactly slow down or stop. Is there a good way to simulate friction as the ball slows down?
Do you mean like Air Friction? RigidBodies already have an Air Drag variable which will make them stop floating indefinitely.
Well I only want it to affect movement in the x and y values. If I can choose which axis to affect on air drag and change air drag from the script then that would be a good choice. I can’t see anything about that specifically on the Unity docs though
Well, it’s easy enough to simulate, you just need to dampen the velocity every FixedUpdate frame.
Is there any good documentation on dampening velocity? I can’t find anything that I can really understand super well atm. Like I get the concept, but I can’t really reproduce the math
You can just do something like rigidBody.velocity = rigidBody.velocity * 0.9f;
and it will eventually get to something close to 0.