unity-game-enginebouncepong

Unity 2D - How does velocity and bouncy physic material causes the ball to change direction everytime it hits something?


So, I'm following a youtube tutorial on how to make pong. I understand and learned alot of stuff but there's a point where he made the ball and its movement but he didn't explain it. He used

void Start() 
{
    rb.velocty = new Vector2(speed, speed);
}

The ball is also attached with a rigidbody2d, a circle collider with a physic material attached. The physic material has a friction of 0 and bounciness to 1. This somehow made the ball bounce off an object.

Can anyone explain to me how it works?

Thanks alot!


Solution

  • See Physic Materials:

    This is all handled by Unity's PhysicsEngine itself so you don't have to worry about that.