Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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:
    21
    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. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    366
    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:
    9
    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:
    21
    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!