- Home /
3D Camera, attached to player, makes game objects jitter when moving the same direction
I am making a game where camera is attached to a player and its a 3rd person view. There are also cars travelling from left to right. When the player stands still or moves left everything is fine. But when the player moves right the cars look kind of buggy, in the sense that instead of travelling continuously they stop and jump forward and so on.
I am using freelook cinemachine camera on my player but the problem was occurring even when I was using regular camera. I recorded a gif of it happening but my computer is slow and the gifs frames are not high enough to show the error. Is the error maybe caused by the fact that I have a slow PC ?
Here are the code and program snippets that might have an effect:
Car movement Code:
public class carMovement : MonoBehaviour
{
public float speed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
transform.position += new Vector3(speed * Time.deltaTime, 0, 0);
}
}
My player is using a character controller and cc is the variable which holds the character controller. Player movement code:
void Move()
{
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Vector3 move = new Vector3(x, 0, z).normalized;
if (canMove&&move.magnitude>0.1)
{
float targetAngle = Mathf.Atan2(move.x, move.z)*Mathf.Rad2Deg+ cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
cc.Move(moveDir * moveSpeed * Time.deltaTime);
}
}
cinemachine freelook properties: http://prntscr.com/ufzpme
script execution order: http://prntscr.com/ufzpsz
gif of problem(not very clear as specified above): https://gyazo.com/43fee55922c33c11a5ec08b0320f12c9
Finally, the problem goes away if I change the car's movement code from FixedUpdate to Update(). I am new to Unity and thought FixedUpdate should be called for framerate independent movement so I thought its the correct thing to use. What is the correct way to solve my problem? Thank you.
Your answer
Follow this Question
Related Questions
Particles lag/stutter - choppy movement 3 Answers
Inversing fixed delta time 1 Answer
Weird MoveTowards behaviour on low fps only. 0 Answers
Camera rotate around a moving object: fixedLateUpdate? 1 Answer
Physics + first person camera = jitter? 4 Answers