Home > Software engineering >  Unity 2D how to stop a ball which bounced by wall
Unity 2D how to stop a ball which bounced by wall

Time:07-19

i have a ball and i'm shooting it with rb2d.addForce to the mousePosition.

if (Input.GetKeyDown(KeyCode.Space))
{
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    _rb.AddForce(mousePos * ballSpeed);
}

When it hit the wall which has a Physics2d with bounciness, it bouncing but going forever. How can i make the ball stop when it travels some amount of distance.

CodePudding user response:

The easiest solution for you is probably to introduce some drag to your ball's rigidbody2d component.

  • Related