I’m making a basic game of pong for practicing using Unity 3D as I’m a nub, but sometimes the ball just loses momentum, Is there any script I can add to constantly keep it at a certain speed or something?
I stumbled upon a similar problem ([here][1]). You can solve that in several ways.
- The totally-physic one : use a non-kinematic rigidbody and in FixedUpdate set the velocity to a constant magnitude (not direction mind you !)
- The half way : Use a kinematic rigidbody and move it in FixedUpdate. You can use OnColliderEnter to know when a collider was hit (you’ll need a non-kinematic rigidbody on it) and then use Reflect on the direction to make the ball bounce.
- The not-physic-at-all way. Done in Update, it uses Translate (or position +=), Reflect and a way to know when the ball isn’t where it should. I used Plane and [GetSide][2].
Good luck !
[1]: Bouncing objects and Energy loss - Questions & Answers - Unity Discussions
[2]: http://unity3d.com/support/documentation/ScriptReference/Plane.GetSide.html