I have a "board" with a ball (rigidbody) moving over it and colliding with obstacles.
I want its velocity magnitude to remain constant throughout time.
How do I achieve this?
What I've tried/achieved so far:
- My first guess was to use OnCollisionExit to set the velocity manually, but that lead to weird physics.
- I don't see how to use AddForce to do this since the previous movement would still be factored.
- To be clear, what i want is to set the velocity at all times to rigidbody.velocity.normalized x magnitude, where magnitude is a float I set previously. This would allow the physics engine to make all impact math to decide the direction of the ball after the collision, but my math would keep the velocity intact.
- I then decided to add UpdatedFixed and on every call set the velocity as stated above. It's working, but feels like a bad hack because I'm updating the velocity every frame and forsaking the physics engine.