Stuttering with moving Rigidbody
Hi! My name is Raúl. First of all, sorry for my english.
I am getting a lot of stuttering when moving my character with rigidbody.MovePosition. I have tried changing the "interpolate" property of the rigidbody to Interpolate and extrapolate, but behaves the same.
My Fixed Timestep is 0.02 (default), if I get this value down, the stuttering stops, but I don't want to use this method because I have to turn the value VERY low to work.
I am using Unity 2018.2
You can see the problem in this videos:
https://www.youtube.com/watch?v=g31P70LFYMc
https://www.youtube.com/watch?v=lEMQtbfS1Fk
The videos are recorded at 60fps but my display is 144Hz and it makes it a lot more noticeable. The first example is a simple Unity camera and the second one is the Cinemachine freelook camera, this one is specially bad.
This is my code for the player movement:
void FixedUpdate()
{
rb.MovePosition(rb.position + this.transform.forward * inputMagnitude * speed * Time.fixedDeltaTime);
}
void Update()
{
// Checks if the player is grounded
isGrounded = Physics.CheckSphere(groundChecker.position, groundDistance, groundLayerMask, QueryTriggerInteraction.Ignore);
// Setup for movement
if (isGrounded)
{
inputs = Vector3.zero;
inputs.x = GamePad.GetAxis(CAxis.LX);
inputs.z = GamePad.GetAxis(CAxis.LY);
if (isCrouching)
{
inputs /= 2;
}
inputMagnitude = inputs.magnitude;
animator.SetFloat("zSpeed", inputMagnitude);
if (mainCamera.isActiveAndEnabled) inputs = mainCamera.transform.TransformDirection(inputs);
inputs.y = 0;
// Rotation changing the forward
if (inputs != Vector3.zero)
{
this.transform.forward = inputs;
}
}
}
Where do you move your camera? Update, FixedUpdate or LateUpdate?
Check this out, unless you already tried this: https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.LateUpdate.html
The thing is that the first camera is not moving and the second one is Cinemachine's Freelook.
I have tried changing the Update property in the Cinemachine Brain to FixedUpdate, LateUpdate and leaving it in SmartUpdate and it behaves the exact same way.
You say your fixed time is set to 0.2. If it's not a typo, then you should change it to default fixed time setting which is 0.02 actually.
I'm sorry, you are absolutely right, it is 0.02, I will correct the typo.
Answer by Saix_93 · Aug 26, 2018 at 10:00 PM
Hi again! I have tried the following:
I have disabled the Auto Simulation in the project settings in Edit > Project Settings > Physics. I moved the part of the code that handles the character movement and rotation to Update and make a call to Physics.Simulate().
This solutions seems to get rid of the stuttering problem, but for some reason, the gravity seems to be doubled when i pass 0.02f to the Physics.Simulation function. (If I pass 0.01f it works fine)
Any ideas why is this happening?
Your answer
Follow this Question
Related Questions
How to fix this problem? 1 Answer
Problem. Pick up and Grab object script, except all objects in scene are picked up instead of one. 0 Answers
Ball Speed is not increasing as per code 0 Answers
Rigidbody jittering (Interpolation set on) 0 Answers
Unity Annoyance with Physics Help C# Scripting Problem Momentum Issue Please Help 0 Answers