Hi, I’m making a Pong game utilizing the physics engine in unity. Problem is that when the ball hits the right paddle, with different angles of incident, it ends up going more or less straight upwards (sometimes even a bit backwards). This does not occur when hitting the left paddle. The paddles are from the same prefab I made.
Setup: I have a cube as my ball, which has a rigidbody and bouncy material. My two paddles also have bouncy material. Gravity is disabled.
Project available here.
Any ideas of what could be wrong? Also let me know if you need more information.
Thanks in advance.
That’s because you are handling the collision in your script, and also it’s being handled by the physics engine. Since you set bounciness to 1, no velocity will be lost in the collision, so simply let the physics engine handle it.
Remove this code altogether:
private void OnCollisionExit(Collision collisionInfo) {
foreach (ContactPoint contact in collisionInfo.contacts) {
GameObject pad = contact.otherCollider.gameObject;
if (pad.name == "Player One" || pad.name == "Player Two") {
//IncreaseSpeed(speedIncrease);
rigidbody.AddForce(speedIncrease, speedIncrease, 0, ForceMode.VelocityChange);
}
}
}