Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

I need help with bouncing ball

Discussion in '2D' started by Okba, Mar 29, 2020.

  1. Okba

    Okba

    Joined:
    Jul 10, 2015
    Posts:
    4
    anyone can help me how to do a bouncing ball with diagonal movement not just up and down in same spot in 2d please i want it to bounce up and down and move left and right until it colid to the next wall.
    if you played an old game arcade named PANG i want to make like it.
     
  2. frasderp

    frasderp

    Joined:
    Oct 6, 2016
    Posts:
    19
    A basic implementation - Add a material to the ball, with 0 friction and bounce of 1.

    Second, you need to add velocity to the ball (which will need a rigidbody also).

    Code (CSharp):
    1. GetComponent<Rigidbody2D>().velocity = new Vector2(3f, 5f);
    Note, the section in Vector2(x, y) are the x and y velocity components.
     
  3. Okba

    Okba

    Joined:
    Jul 10, 2015
    Posts:
    4
    can you make me a picture or a little video pelase?
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Okba

    There are like, several Unity tutorials on this topic - did you actually do a google search before asking this question?

    It would take only 5 seconds of your time, and searching before asking is recommended here in the forum guide lines.