How to set constant speed for a ball

Hello, I’m working on a basic breakout style game and I’m using the physics to simulate the ball movement. I tried to use projectile component but it’s harder to control (i think) once you shoot the ball, that’s why I’m not using it now.

My question is, I’m able to read the velocity of the ball each tick but not override it. Set Physics Linear Velocity always sets it to 0 somehow. What am I missing?

1 Like

Hello, I am guessing the only force acting on the ball is gravity, if that is so, untick “Enable Gravity” or call “Set enable gravity” node in blueprint and set it to false. If gravity is disabled, please write about other forces that are constantly applied to the ball.

Thanks for the reply. I’m not using gravity because I don’t need the ball to go down, I need it going at a constant speed and bouncing off stuff.

Edit: The ball is spawned with an “Add Impulse” node and it works but after that I can’t limit the ball’s speed and it gains too much speed if I hit it with the paddle.

Is it currently accelerating/decelarating, or bouncing off with a different speed than before?

Edit: You can create a variable “ConstantSpeed” and set the speed of the ball after each hit to that variable.

Also if you can make projectile movement work, it would be much easier

Hey @osmanzort!

A few questions:

  • Have you tried to output your “direction” value to see what the log shows?
  • What is your speed variable set at? It is at the same value so are you sure it isn’t currently 0?

Any additional specifics you provide may go a long way in solving your problem!

It displays the correct value at ball launch. Also, after trying it with “on event hit” instead of every tick it works. I guess it has something to do with how tick works in Unreal, I’ll try changing the code and maybe use plain movement instead of physics. Thanks for the help.

1 Like