- Home /
How can I make a rigidbody stop with the user input and ignore its kinetic energy?
My goal is to move the character (currently a capsule) at constant/fixed speed in the direction the player wants to. When the player stops giving inputs, the character should instantly stop moving, however it currently keeps "sliding away" when I drop inputs because it has gained kinetic energy. How can I make it ignore that energy and stop it right away?
Controller script:
// the player willingly moves and rotates according to camera rotation
// I have also set constraints on the X and Z rotation values on the rigidbody component
// this is a third person view game
private void FixedUpdate()
{
rotate();
Vector3 vert = getAxis("Vertical") * cameraTransform.forward;
Vector3 horz = getAxis("Horizontal") * cameraTransform.right;
rb.AddForce((vert + horz).normalized * speed, ForceMode.Impulse);
}
// todo: look towards the movement vector, reset to camera fwd when there is no movement
void rotate()
{
Vector3 lookpos = transform.position + cameraTransform.forward;
lookpos.y = transform.position.y;
transform.LookAt(lookpos);
}
int getAxis(string name)
{
return Input.GetAxisRaw(name) > 0 ? 1 : Input.GetAxisRaw(name) < 0 ? -1 : 0;
}
Properties of the character's rigidbody:
I have also attached a Physics Material to the character's Capsule Collider:
Your answer
Follow this Question
Related Questions
Boat collides with track(plane) below it while moving forward 0 Answers
Realistic player movement? 2 Answers
Having problems with animation and movement of 2D Character 0 Answers
Constant time way to find intersection of two objects when given speeds and directions of both? 3 Answers
Stopping my player from moving when hitting a wall. 5 Answers