I'm learning Unity by creating a simple 2D bat & ball prototype game. A ball (Rigidbody2D with sphere collider and a bouncy Physics 2D Materia) is dropped under gravity from a height, and bounces off a player-controlled bat, which is moved via the mouse. It works fine with Discrete Collision Detection set on the Rigidbody2D component, but can graphically over-shoot the bat sometimes. A Brackey's tutorial mentioned setting the Collision Detection to Continuous to get more accurate collisions, but when I do this on the ball, it will bounce the first time, but on the second collision with the bat, the y velocity gets set to zero (according to a Debug.Log call), and it therefore stops bouncing. I'm not touching the velocity in OnCollisionEnter2D, leaving everything to the built in physics engine. The Balls also has an empty Update() function, so nothing going on there.
What can be causing the y velocity to suddenly disappear when setting the RigidBody2D Collision Detection to Continuous, and what is the correct way to solve this?
Cheers.
↧