- Home /
Have something never lose momentum?
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?
Answer by Berenger · Mar 23, 2012 at 11:41 PM
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]: http://answers.unity3d.com/questions/205803/bouncing-objects-and-energy-loss.html [2]: http://unity3d.com/support/documentation/ScriptReference/Plane.GetSide.html
Your answer
Follow this Question
Related Questions
Right Click to Ignore All But Terrain, How? 1 Answer
How to count collisions of the same tagged objects? 2 Answers
hit.gameObject.tag 2 Answers