c# - Why does my character/camera stutter in Unity 2d? -
ever since i've added new camera script, character (which camera trying follow) keeps on stuttering when moving. if keep character still, won't stutter anymore.
using unityengine; using system.collections; using system.collections.generic; public class camerafollow : monobehaviour { public transform lookat; private bool smooth = true; private float smoothspeed = 0.1f; private vector3 offset = new vector3 (0, 0, -6.5f); void lateupdate() { vector3 desiredposition = lookat.transform.position + offset; if (smooth) { transform.position = vector3.lerp (transform.position, desiredposition, smoothspeed); } else { transform.position = desiredposition; } }
}
please - it's driving me crazy! edit: ignore error @ bottom - it's part of else i'm working on.
edit2: never mind, turning on interpolation in rigidbody2d fixed it! help!
first of all, make sure code changing position of lookat transform running in update() , not lateupdate().
if case or didn't solve problem, try running code shown in fixedupdate(). don't know why, should work.
Comments
Post a Comment