- Home /
Camera flickers between scenes
So I have a camera that moves forward by set increments every time my player leaves its viewport. It works fine, except if I get my player to stand just between one viewport and the new one, the camera flickers between the two scenes. Is there a way to fix this? I have a way to set scripted camera scenes too, and those don't experience the same flickering because I set them manually, and I have a one-way barrier that doesnt allow the player to go back once they've entered a scripted scene.
using UnityEngine;
using System.Collections;
public class CameraScript : MonoBehaviour
{
private bool isScripted=false;
private int sceneNumber=0;
public Transform target;
void Update()
{
//this sets the left and right border to whatever the camera can see on the left and right sides
Vector3 rightBorder=camera.ViewportToWorldPoint (new Vector3(1,1,1));
Vector3 leftBorder=camera.ViewportToWorldPoint (new Vector3 (0,0,0));
//this makes it so that if the player hits the left or right border, the camera moves over to compensate.
if (target.transform.position.x >= rightBorder.x && isScripted==false)
{
transform.position=new Vector3 (rightBorder.x + 7f, transform.position.y, transform.position.z);
sceneNumber++;
}
if (target.transform.position.x <= leftBorder.x && isScripted==false)
{
transform.position=new Vector3 (leftBorder.x - 7f, transform.position.y, transform.position.z);
sceneNumber--;
}
if (sceneNumber==2)
{
isScripted=true;
transform.position=new Vector3 (34f, -6f, -10f);
camera.orthographicSize=10;
}
}
}
Answer by TaylorAnderson · Aug 07, 2012 at 07:29 PM
i think im just going to drop the code and make it more scripted instead. thanks for the help
Answer by ScroodgeM · Aug 01, 2012 at 09:25 PM
just added 1 word 8)
using UnityEngine; using System.Collections;
public class CameraScript : MonoBehaviour { private bool isScripted=false; private int sceneNumber=0; public Transform target; void Update() { //this sets the left and right border to whatever the camera can see on the left and right sides Vector3 rightBorder=camera.ViewportToWorldPoint (new Vector3(1,1,1)); Vector3 leftBorder=camera.ViewportToWorldPoint (new Vector3 (0,0,0));
//this makes it so that if the player hits the left or right border, the camera moves over to compensate. if (target.transform.position.x >= rightBorder.x && isScripted==false) { transform.position=new Vector3 (rightBorder.x + 7f, transform.position.y, transform.position.z); sceneNumber++; }
else if (target.transform.position.x <= leftBorder.x && isScripted==false) { transform.position=new Vector3 (leftBorder.x - 7f, transform.position.y, transform.position.z); sceneNumber--; }
if (sceneNumber==2) { isScripted=true; transform.position=new Vector3 (34f, -6f, -10f); camera.orthographicSize=10; }
}
}
i just tried building the game, and with the extra black space on either side the camera flicker gets really bad, even with the one word added. ideas?
i don't clearly understand what type of flickering you are talking about. explain please. images will be the best.