Throw an object following a curve in 2D

Hello,

I am trying to create a pong template, with the twist of being able to curve the ball with the paddle. Imagine this classic game: http://www.curveball-game.com but in 2D.

Everything in my scene is kinematic, except for the ball, so when the scene starts, I addForce to the ball’s rigid body and it bounces on the bounds and paddle.

In order to calculate how big the curve should be, I am saving the last 10 values of the paddle’s position inside fixedUpdate. Therefore, at the moment of the impact I know how fast the paddle was moving and apply an appropriate curve.

This is where my question starts. In my first implementation, I am using AddRelativeForce inside the ball’s FixedUpdate, pointing to the left or the right (depending on the paddle’s direction during the impact), in order to simulate a curve. But this constant force is messing with the ball’s velocity, meaning I am experiencing an acceleration every time I am curving the ball.

I want to be able to control the maximum velocity of the ball at any time. Should I abandon the addRelativeForce solution? What is the best way to achieve this behavior?

Thanks!

One option is to use ClampMagnitude on the ball’s velocity each frame, or after any velocity change, to limit the maximum speed it can go.

ball.velocity = Vector3.ClampMagnitude(ball.velocity, maxSpeed);