having CharacterController movement in fixedupdate causes jerky movement on camera
Hi, im having a really big headache because of this problem, im been sitting with this for a week and can't find any solution at all.
let's say you take the standard unity FirstPerson-CharacterController asset and put it in the scene, and then start walking in a circle by holding "A" and move the mouse in a direction so that the character makes a circle,now if you look at the ground infront of you on the terrain, it starts tearing, and all the movements is jerky and laggy(EVEN WITH HIGH FPS).
and when i change and put all the movement code in the update() function istead of the FixedUpdate()(wich you shouldn't do) it becomes smooth as hell, but then the problem instead is that when i get high fps i run faster and with lower fps i run slower, i literally think im gonna die, im so freaking mad please help me.
i have a good setup, good monitor and mouse and keyboard. nothing is wrong with my setup.
Have you tried turning on the Interpolation on the character under Rigidbody? http://docs.unity3d.com/ScriptReference/Rigidbody-interpolation.html
Hello, thank you for answering, and yes i have tried that, it is still laggy and im not really using rigidbody, only a charactercontroller and the standard script for the physics..
please if you have any other solution ANY i really need to know :/
Answer by big_rip · Jan 04, 2017 at 12:09 AM
This is old, but I still had this issue in 2017. What helped me:
set Fixed Timestep to 0.008333334 (120 FPS)
turn V-Sync on
HOLY JESUS, this actually worked out !!!!!!!
i am so glad you gave this information, thank you so so so much!
just want to let you know that this is not a very good solution. running physics faster cost more performance and the only reason one should do that is when collisions are not properly solved anymore.
Answer by hexagonius · Mar 12, 2016 at 04:38 PM
If you run on different speeds if framerate differs the movement is not delta time based. whatever way you calculate the moving speed, multiply it with deltatime. another thing could be the camera that is not repositioning (if it's a follow cam) in LateUpdate instead of any other update
void $$anonymous$$ovement()
{
float speed;
GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desired$$anonymous$$ove = transform.forward * m_Input.y + transform.right * m_Input.x;
if (m_CharacterController.isGrounded)
{
m_Jumping = false;
}
if (m_CharacterController.isGrounded)
{
m_$$anonymous$$oveDir.x = desired$$anonymous$$ove.x * speed;
m_$$anonymous$$oveDir.z = desired$$anonymous$$ove.z * speed;
}
m_CollisionFlags = m_CharacterController.$$anonymous$$ove(m_$$anonymous$$oveDir * Time.fixedDeltaTime);
//UpdateCameraPosition(speed);
if (!m_CharacterController.isGrounded)
{
if (anim != null)
{
anim.SetBool("Falling", true);
}
}
else
{
if (anim != null)
{
anim.SetBool("Falling", false);
}
}
}
this is my movement function, what should i change? ( i update this in the Update function)
m_CollisionFlags = m_CharacterController.$$anonymous$$ove(m_$$anonymous$$oveDir * Time.deltaTime);
changing Time.FixedDeltaTime to just Time.deltaTime might solve your issue, if not it might be within m_CharacterController's $$anonymous$$ove function.
Answer by collederas · May 10, 2020 at 09:37 PM
Hey, it's late but for anyone dealing with the same problem, I think this blog post will be interesting:
http://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8