Search Unity

Bouncy Balls

Discussion in '2D' started by circleline, Jan 20, 2015.

  1. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Hey, I'm a real newbie in Unity2d and my question is how can i make a sprite(Ball) move across the screen like
    ? I added sprites to the side of the wall and colliders too. My problem is that when i run the game the ball just bounces up and down and nothing else.


    Thanks!
     
  2. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Bump! Really need this
     
  3. DustyMcp

    DustyMcp

    Joined:
    May 23, 2013
    Posts:
    25
    If im not incorrect maybe you could add a physics material and a rigidbody to it, then choose the bouncy one, and they should bounce all over the place.
     
  4. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    I tried it, it's bouncing only Up and Down
     
  5. Senladar

    Senladar

    Joined:
    Jan 1, 2015
    Posts:
    45
    They only go up and down because of gravity.

    Try setting gravity to zero on the rigidbody and using AddForce to move them.

    When they collide with a wall, have them pick a random direction in a 180 degree radius that is opposite from where it hit (I.E. if it hits at 90 degrees, addforce to a random degree between 270 and 360)

    If they all have colliders on them, hitting each other should already be handled by the physics system.
     
  6. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    ^ Thanks! I got a new problem, sometimes the ball hits the wall(collider) perpendicularly, this causes the ball to bounce back and forth in a straight line. What code should i write so that whenever it's like this then change angle or ball.
     
  7. circleline

    circleline

    Joined:
    Nov 29, 2014
    Posts:
    42
    Another Problem, How do i increase the speed of the ball while in-game? I tried making tweaks to the mass in-game but it doesn't make a different