Tuesday, January 19, 2016

unity - Smooth Camera Follow


I am using a fixed static background. I have a gameobject(Current ref. image) which is moving with the help of waypoints. I have made camera to follow the Current. The camera is stuttering while moving. Can anyone help me to solve the camera stuttering and make it follow the Current smoothly?


This is my code attached to camera following the star


public class CameraController : MonoBehaviour {

void Start () {
GameObject.FindGameObjectWithTag("OptionCamera").GetComponent().orthographicSize =
(20.0f / Screen.width * Screen.height / 2.0f);

}

void LateUpdate() {
if (GameObject.FindGameObjectWithTag ("Current") != null) {
if (GameObject.FindGameObjectWithTag ("Current").GetComponent().Greenblast == false &&
GameObject.FindGameObjectWithTag ("Current").GetComponent().Redblast == false)
{
Vector3 pos = GameObject.FindGameObjectWithTag ("Current").transform.position;
transform.position = new Vector3 (transform.position.x, pos.y, transform.position.z);
}

}
}
}

Example of Camera movement




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...