Maintain Rigidbody Speed in Collision

Supposed a character in 3D moved with an analog pad with a fixed speed = 10 towards a wall at 45 degree.

When the character collides, if the analog direction is still at 45 degree, character’s speed will be reduced

  • Can I maintain the character’s speed while it’s collides with the wall?

  • What is the term of this? (search keyword, I’m not a native English speaker and bad with physics)

  • Can it be done with changing some parameters at the physic material or manually change the velocity according the collision angle?

  • Is there a better way?

Character moved with RigidbodyFPSWalker (http://wiki.unity3d.com/index.php?title=RigidbodyFPSWalker) which worked perfectly.
RigidbodyFPSWalker

...
       // Calculate how fast we should be moving
        var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        targetVelocity = transform.TransformDirection(targetVelocity);
        targetVelocity *= speed;

        // Apply a force that attempts to reach our target velocity
        var velocity = rigidbody.velocity;
        var velocityChange = (targetVelocity - velocity);
        velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
        velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
        velocityChange.y = 0;
        rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
...

bump :frowning:

didnt test, but does putting a physics material on the wall that has no friction and friction combined set to minimum do the trick?

Its very easy, get velocity magnitude a frame before collision, and after collision use current rb normalized velocity * your saved velocity magnitude that you setted before collision.

1 Like

unfortunately it doesn’t.

nice concept! solved my problem.
Thanks!