How to set velocity to a previouse value

Hi all

I am making a small pong style game and have a problem when the ball hit the paddle at the bottom it will some times slow down. Guessing it’s when I move it as the ball is hitting it.

I have stored the last correct velocity in a vector3 and want to set it if the ball speed drop below that value.

If I just set the velocity of the rigidbody on my ball to my saved velocity, it also changes the direction of the ball to what it was when I stored it.

How do I keep my ball direction, and only set the velocity of the ball to my stored vector3?

Thx
Rasmus

How do I keep my ball direction, and only set the velocity of the ball to my stored vector3?

Velocity represents both speed and direction, which means you are implicitly assigning a direction when you assign velocity.

If I had to guess, you actually want to keep the old speed, but move in the current direction? If so, some quick vector multiplication can achieve that:

//produce a new velocity vector:
//  - use same magnitude (speed) as current velocity
//  - use previous direction
rigidbody.velocity = rigidbody.velocity.magnitude * lastVelocity.normalized;