- Home /
2D Camera Follow - Jittery?
Hi guys!
I'm having a small problem with my camera follow script. Every few seconds the camera jitters on the x axis, but I'm not sure why.
Here is my script so far:
public float addPos;
public Transform target;
public GameObject asteroid;
void Update(){
asteroid = GameObject.Find("Sphere(Clone)");
}
void LateUpdate () {
if(gameObject.name == "Main Camera"){
if(!Astronaut.isDead){
transform.position = new Vector3(target.position.x + addPos, transform.position.y, transform.position.z);
}else if(asteroid != null && Astronaut.isDead){
transform.position = new Vector3(asteroid.transform.position.x + addPos, transform.position.y, transform.position.z);
}
}
if(gameObject.name == "Score" && !Astronaut.didStart){
transform.position = new Vector3(target.position.x, transform.position.y, transform.position.z);
}
}
I've tried changing the LateUpdate to Update/FixedUpdate (didn't solve anything), and I also set most of my RigidBody's to Interpolate (made it a little bit better).
I really hope that you guys can help me!
-Collin
Edit I forgot to mention, but the problem only happens when the player screen wraps, it causes the asteroids to jitter. Here is a .gif of what it looks like: https://twitter.com/Slader166/status/561758957916946432
Answer by Applefruits · Feb 03, 2015 at 11:28 PM
transform.position = Vector3.Lerp(transform.position, target.position, 0.1f * Time.deltaTime);
maybe lerp im a newb to but :$
Applefruits has the right idea. (I edited your sample to make it framerate independent.) Interpolating camera movement is essential.
Is it possible for the camera to follow without the Lerp? I don't exactly want it to be that smooth.