# How to make my character slide (not bounce) off a slope

My character needs to slide and not bounce off a slope.

The solutions I found here use a Reflection vector, but they make my character bouncy when they run downwards a slope.

var reflectVector = normal.clone().multiplyScalar(-this.velocity.clone().dot(normal));


How can I make my character simply stick to the terrain when they walk?

• Use Box2D and set the body's restitution to 0. Sep 4, 2012 at 20:19
• Using 3D :P but I drew this diagram to make it more easy to understand. Thanks though
– Nick
Sep 4, 2012 at 21:02
• How about use bulletphysics and set the restitution to 0? PS. I like physics engines. Sep 4, 2012 at 21:08
• @ClassicThunder Suggesting a physics engine for a simple vector math problem is an overkill. It's good to learn the math first. Of course it's good to learn physics engines as well, but I wouldn't go that far yet. Sep 5, 2012 at 4:31
• @msell "a simple vector math problem" Its never just 1 simple vector math problem. Anyways it was just a reminder that he is reinventing the wheel. Sep 5, 2012 at 7:01

Eliminate the normal component from the old velocity using vector projection to get the desired velocity. Assuming normal is a unit vector, the formula is:

desiredVelocity = oldVelocity - dot(normal, oldVelocity) * normal;


Applying gravity should accelerate the desired velocity, or if you just want constant speed, normalize it and scale as you wish.

You can also think this as a case of reflection. Reflection is oldVelocity - 2 * dot(normal, oldVelocity) * normal;. Here 2 can be replaced with (1 + e), where e is elasticy in the range [0, 1]. With 1 you get the perfect reflection and with 0 you get the formula above with your desired result. With a value between 0 and 1 you get small bounce.

here is pseudo code of one way it can be accomplished.

float speed = oldVelocity.Length();
tempVector = cross(oldVelocity, normal);
desiredVelocity = cross(normal, tempVector);
desiredVelocity.normalize();
desiredVelocity *= speed;