- Home /
unity2d change angular direction
Hello
I have been having a bit of trouble with this for a while now, my problem is in a "breakout" style game where the ball will be hitting the paddle from multiple angular directions. But as the ball hits the object I need it to change its angular direction described in the pic below
I have tried to fix this by rotating the ball when it hits the paddle/player and then adding a new force but that didnt seem to work, I was wondering how this could be accomplished.
.
Answer by robertbu · Apr 15, 2014 at 03:33 PM
You can change the Rigidbody.velocity. You can get the new angle using Vector3.Reflect(). You will need the normal (line in the middle) to make the calculation. Assuming the paddle is horizontal, the calculation would be:
rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, Vector3.up);
But why are you doing the calculation instead of just letting Unity's physics (2D or 3D) do the calculation?
To your question unitys physics2d does not do the calculation does not work for some reason it will just bounce straight. I will try your solution
thank you finally got it to work, been stuck on this forever.