- Home /
Why is my camera motion so jittery?
I have been working on trying to smooth out my camera motion for my game for days and I cannot get it to a reasonable level of smoothness. Are there any corrections to this code that I can make that will improve the smoothness? I have tried the moveTowards() function as well and it didn't help.
/ CAMERA MOVEMENT */
void FixedUpdate () {
//Do we need to spawn new platforms yet?
Vector2 playerHeight = playerTransform.position;
if (playerHeight.y > nextPlatformCheck) {
PlatformMaintenaince (); //Spawn new platforms
}
//Update camera position if the player has climbed
Vector2 currentCameraHeight = transform.position;
if (playerTransform.position.y > currentCameraHeight.y)
{
transform.position = Vector2.Lerp(new Vector2(transform.position.x,0.0f), new Vector2(0.0f, playerHeight.y), smooth * Time.deltaTime);
}
else {
// If player is too low, gameover.
if ((playerHeight.y) < (currentCameraHeight.y - 5.5)) {
GameOver();
}
}
}
Answer by aman_jha · Aug 05, 2014 at 02:03 AM
Maybe it's because it's in FixedUpdate(), try putting it in Update ()
Answer by Nexus2911 · Aug 05, 2014 at 03:00 AM
Does your player have a RigidBody2D component? If so, change the Interpolate drop down box value from "none" to "interpolate."
I was having very jittery camera movement and this solved it.
I tried this but it completely messed up my character movement
Answer by eelstork · Aug 05, 2014 at 03:01 AM
Put it in LateUpdate()
Yikes, I've got some serious jitter action inside of LateUpdate()
I'm reading about LateUpdate() in the docs and it says it should always be used for a camera follow script. I'll play around with it for a bit but right now it doesn't seem to be helping