- Home /
Gameobject flickers on camera follow. Solved but with silly method :/
im making an endless runner game, and everytime I play the game the runner was flickering. But at gameplay when I disable and re-enable the camera follow script component in the camera. the flickering just fixed. so I make a method to disable the camera follow script component at the start of the game and then re-enable it after a certain amount of time just to make the flickers go away. (silly method but works just fine)
I've tried a lot of different way from tweaking the setting to manipulating camera object, but no other solutions. (I even uninstal & re-instal unity ==`)
So I need to know why this is happening, is it a bug? and if there is another solution I'd like to know... I also leave the camera component setting to default.
This is the Player Script
private CharacterController controller;
private Float speed = 10;
private GameObject camFol;
private bool moving;
void Start () {
controller = getComponent<CharacterController> ();
camFol = GameObject.FindGameobjectWithTag("MainCamera");
camFol.GetComponent<CameraFollowScript>().enabled = false;
}
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
controller.Move (vector3.forwad * speed * time.deltatime);
Moving = true;
if (Moving)
camFol.GetComponent<CameraFollowScript>().enabled = true;
}
& this is the Camera follow Script
private Transform lookAt;
private vector3 startPosition;
void Start () {
lookAt = GameObject.FindGameobjectWithTag("Player").transform;
startPosition = transform.position - lookAt.position;
}
void Update () {
transform.position = lookAt.position + startPosition;
}
Yeah, what everyone below posted. I'll elaborate as to why for you. What's happening is the scripts are competing against each other basically, it needs to be the FixedUpdate or LateUpdate because this runs after the regular update, if they're running at the same time it's like you camera is trying to follow something that hasn't fully moved yet basically.
Answer by aditya · Aug 17, 2016 at 01:44 PM
In Player script put your character movement code in FixedUpdate and in Camera follow script put the code that is updating the position of camera in FixedUpdate too
Answer by diedona · Nov 06, 2018 at 11:30 PM
I had the same problem, but solved it by putting camera code into LateUpdate and Player Script in Update.
Answer by $$anonymous$$ · Nov 07, 2018 at 12:08 AM
anything that involves physics goes into FixedUpdate
Your answer
Follow this Question
Related Questions
Smooth camera on moving platform 1 Answer
How to make a camera zoom in on a specific point 1 Answer
Follow camera in 2d game 2 Answers
URGENT Cinemachine virtual camera while falling 1 Answer
Top down camera lock 2 Answers