- Home /
How to make collision for character controller with moving objects smooth?
Hello, I have a problem with my first-person character controller where the collision between the controller and moving objects (like nav mesh agents and doors) is not smooth. When the door or nav mesh agents push the character controller, the character controller stutters, and the collision is not smooth. Below is a video of the problem that I am describing:
https://www.youtube.com/watch?v=og-Ini9KwAY
The character controller is using a rigidbody that has isKinimatic set to true. Changing the values on the character controller component did not smooth out the stuttering. Below is a short snippet of the code that moves the character controller and the components for the rigidbody and character controller.
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
inputXY = new Vector2(horizontalInput, verticalInput);
if (inputXY.magnitude > 1) { inputXY.Normalize(); }
speed = walkByDefault ? isCrouching ? walkSpeedInternal : (isSprinting ? sprintSpeedInternal : walkSpeedInternal) : (isSprinting ? walkSpeedInternal : sprintSpeedInternal);
if (!onStair)
{
move = (transform.forward * inputXY.y + transform.right * inputXY.x) * speed * Time.deltaTime;
}
else
{
forwardDir = Vector3.ProjectOnPlane(transform.forward, groundNormal).normalized;
move = (forwardDir * inputXY.y + transform.right * inputXY.x) * speed * Time.deltaTime;
}
velocity.y += gravity2 * Time.deltaTime ;
if (playerCanMove)
{
controller.Move(move);
controller.Move(velocity * Time.deltaTime);
}
I think it may have to do with the physics system not being able to properly detect the collision between the character controller and the door/nav mesh agents but I'm not entirely sure how to resolve that. Any help would be appreciated. Thanks!
Your answer
Follow this Question
Related Questions
Gun collision problem 3 Answers
Non slippery movement 1 Answer
Character Physics 0 Answers
How to change the movement speed of a character 4 Answers
Gravity and rotation control 0 Answers