Constrain rigidbody reflection?

I have a rigidbody character that is always moving forward, and the player controls the left and righ movement. When it hits the walls on the left or right side the script does a reflect:

rigidbody.velocity = Vector3.Reflect(transform.position,collInfo.contacts[0].normal*1.2);`enter code here`

This is working, but I want to limit the object from bouncing backwards, or even directly left or right.

The end result should be if the character hits the right wall it bounces left and sightly forward and vice versa.

Thanks in advance,


This is wrong: you should reflect rigidbody.velocity, not transform.position, and along the normal (multiplying the normal by some constant doesn’t make any difference):

  rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, collInfo.contacts[0].normal);

I suppose this will solve your problem: the way you did that would give crazy results depending on the object position relative to zero. It’s not your fault: the docs example is incredibly bad! Vector3.Reflect is intended to be used with vectors, not points.