- Home /
2D Ball Bouncing Angle Problem (Without Rigidbody)
Hey everyone, I've been working on a simple 2D Pong-styled thing as part of practice. I've been trying to get the whole bounce-"physics" stuff without using a Rigidbody. While my current script works correctly a good amount of the time, every couple of bounces it bounces in an odd, incorrect angle. Now these incorrect angles are generally 'reversed', meaning that instead of bouncing up, it'll take the same angle but downwards; as shown in the following image:
The green line is the angle it's supposed to take, the red line is the angle it actually end up taking. I would guess this is caused by a positive/negative number thing going wrong somewhere, but I'm unable to figure out where. Below here is some Debug output for this specific bounce case, as well as the code.
OnHitObject (ref RaycastHit2D hit) {
Vector2 incomingVec = hit.point - (Vector2)transform.position;
Vector2 reflectVec = Vector2.Reflect (incomingVec, hit.normal);
float turningAngle = Vector2.Angle (incomingVec, reflectVec);
transform.rotation = Quaternion.Euler (0, 0, turningAngle + transform.rotation.eulerAngles.z);
}
So the question is: what's the cause of the angles getting messed up?
Thank you very much in advance for any help or advice.
Your answer
Follow this Question
Related Questions
Vector-based Pong-ball bounce calculations 1 Answer
Paper Ball Physics Implementation 0 Answers
Prevent ball from going straight on x and y axis 2 Answers
What is the best way to move a paddle accurately in a circle? 2 Answers
Ball Aiming System 2 Answers