Now that I’ve had time to read up on using Unity I’ve started tinkering with making my own games, and for the first one I went with a Pong variant just because everyone always says to start there. 
It works - mostly. It’s single player, so there are 3 walls for the ball to bounce against: the top and the two sides. Bounces against the side walls behave as I expect, but bounces against the top wall do not. The direction of the ball after the bounce is always aligned with the normal to the wall. So if the ball hits at 45 deg angle I would expect it to come off the wall at 135 deg, but instead it comes off at 90 deg. All. The. Time.
This is very frustrating and I don’t know what settings I should be looking at in Unity to correct this. The board is aligned in the X-Z plane, so the ball is bouncing off of the x=14.0 plane. Is there something magical in Unity about bounces against an x=constant plane?
I’m quite confused by this behavior.
Of course right after posting that I figured it out. I had the balls’ rigidbody set to freeze rotation in all directions. I turned that off and everything started working the way I expect.
/Emily Latella Never mind.
Grrr! That didn’t quite fix it. It is still bouncing towards the normal instead of the reflection, but it just takes longer to damp down to the normal.
OK. Now I really do seem to have a solution. (Or should I say “workaround”?) I calculate the bounce by hand in the ball object’s movement script.:
void OnCollisionEnter( Collision col ) {
Vector3 temp = Vector3.Cross( col.contacts[0].normal, rb.velocity );
Vector3 tangent = Vector3.Cross( col.contacts[0].normal, temp );
Vector3 tangent_component = Vector3.Project( rb.velocity, tangent );
Vector3 normal_component = Vector3.Project( rb.velocity, col.contacts[0].normal );
rb.velocity = tangent_component + normal_component;
}
It still seems strange to me that I have to do this. I really expected the Physics engine to handle this for me.
1 Like
How about playing with custom physics material?
Thanks but I already added a custom physic material to make it bouncy. The problem was happening in spite of that. The material has the following settings:
Dynamic Friction 0
Static Friction 0
Bounciness 1
Friction Combine minimum
Bounce combine maximum