How could I make a bouncy object move mostly along the Z axis?

So I have this ball, that I want to move along the long hall, at the end of which is a target.

So far I’ve managed to make the ball bounce, but it always ends up bouncing along the X and Y axes.
How could I make it bounce while still keeping most of the forward facing momentum (along the Z axis) ?

Hiya!

Are ya using a Rigidbody for the bounce? If so, if you want to totally remove movement on axes other than the Z axis, you can freeze its position of it on target axes under ‘Constraints’ in the inspector on the Rigidbody component.

If you don’t want to totally remove the movement and just lessen it, what you could do is do something like:

Vector3 objVelocity = rb.velocity; 
objVelocity.x /= 2.0f;
rb.velocity = objVelocity;

With something like this (maybe put in your FixedUpdate function), any velocity in the X direction is constantly cut in half until it is pretty much nothing. This way, the velocity will be mostly in the other directions. You can obviously modify how much you cut it by. Doesn’t half to be half. Hopefully that gives you some ideas!