- Home /
Question by
knarola · Aug 03, 2015 at 05:28 PM ·
unity 5cameracamera-movement
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<Camera>().orthographicSize = (20.0f / Screen.width * Screen.height / 2.0f);
}
void LateUpdate()
{
if (GameObject.FindGameObjectWithTag ("Current") != null) {
if(GameObject.FindGameObjectWithTag ("Current").GetComponent<CurrentController>().Greenblast == false &&
GameObject.FindGameObjectWithTag ("Current").GetComponent<CurrentController>().Redblast == false)
{
Vector3 pos = GameObject.FindGameObjectWithTag ("Current").transform.position;
transform.position = new Vector3 (transform.position.x, pos.y, transform.position.z);
}
}
}
}
screen-shot-2015-08-03-at-10503-pm.png
(25.7 kB)
Comment
Answer by Requiem36 · Aug 04, 2015 at 12:58 PM
If the gameObject you're following have a Rigibody on it, you better use FixedUpdate() to put the code you do the following in.
It is just an image with collider. It does not have RigidBody.
Answer by Sharpless512 · Aug 05, 2015 at 09:37 AM
Maybe lerp your camera movement instead of teleporting to exact coordinates
Your answer
![](https://koobas.hobune.stream/wayback/20220611234209im_/https://answers.unity.com/themes/thub/images/avi.jpg)