Search Unity

How can I preserve a bouncing ball's velocity?

Discussion in 'Physics' started by gameangel147, Jun 6, 2018.

  1. gameangel147

    gameangel147

    Joined:
    Oct 16, 2016
    Posts:
    26
    My brickbreaker game has a ball and an ability that summons apples to act as extra balls. I gave the ball a circle collider and the apples a polygon collider so that they can rotate as they bounce. Unfortunately they are losing velocity when they collide at a wrong angle or with each other or with the ball.

    With the ball, I only set the velocity when launched and left it at that, as I didn't need to preserve the velocity. I've thought about using "this.rigidbody2D.velcoity.x" and so on to keep the values at what I set them to but it's not working.

    Is there a command or some way to keep their velocity constant?
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    In the physics settings or the physics material there's a value for this called bounciness or something, is it set to max?
     
    gameangel147 likes this.
  3. jbaumer6

    jbaumer6

    Joined:
    Mar 12, 2018
    Posts:
    15
    If you are grabbing the velocity from an Update() method, you are going to continually get a new velocity. You'll want to use a bool flag to take a snapshot of the objects velocity where you want it, then apply that value in an Update() method until you don't want it anymore.
     
    gameangel147 likes this.
  4. gameangel147

    gameangel147

    Joined:
    Oct 16, 2016
    Posts:
    26
    It's not. I kept it at just the right amount so that it wouldn't go too fast. Is there a way to increase bounciness in a script?

    Alright, I was just wondering if there was a specific command to deal with that, but that sounds like a simple enough alternative. Since it's an ability, I can just adjust the velocity for the ability's duration.

    Thank you guys!