0
\$\begingroup\$

I am making a simple breakout game. I have added bounce physics to the ball and to the bricks. When the ball collides with the bricks, the speed of ball slows down. I want ball to maintain its speed to what I set it to intially.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ What have you tried? Why didn't it work? Show your relevant code. We can't guess what's going wrong. \$\endgroup\$
    – user35344
    Jun 4, 2016 at 12:11
  • \$\begingroup\$ Is there a way of changing speed of the ball at any time? I want to change the speed after collision. \$\endgroup\$
    – Mazim Arif
    Jun 4, 2016 at 12:35
  • \$\begingroup\$ This is a great place to implement atan2. Here's a video that describes how to achieve this in great detail: youtu.be/u_p5H0wEN8Y \$\endgroup\$
    – Mike
    Apr 24, 2022 at 20:53
  • \$\begingroup\$ @Mike You can do this without trigonometry. ball.velocity = ball.velocity.normalized * speed suffices. \$\endgroup\$
    – DMGregory
    Apr 24, 2022 at 20:59

1 Answer 1

1
\$\begingroup\$

Set a new Physics Material on both the ball and the object you are colliding with. Make sure you set the Friction parameters to 0 and Bounciness to 1.

(Alternatively, you can apply the material to just one side of the collision, with the Combine parameters set to "Maximum" so it overrides the material of anything it collides with)

\$\endgroup\$
1
  • \$\begingroup\$ Done already. Speed is still changing. \$\endgroup\$
    – Mazim Arif
    Jun 4, 2016 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .