I’m using a box collider to detect when my player has entered a specific area on the level. At that point I am using the trigger to call a camera zoom. This is so the camera will zoom in at the end of the level. I believe the trigger is getting called again and again while the player is inside the box collider, causing the zoom to be called endlessly ( and the camera to be shakey). The zoom works great when attached to a key to call it (which is where I found the example) and is stable when zoomed in. But when it’s attached to a box collider trigger its not so usable.
Does anyone have a suggestion that might help?
Here is the script attached to a box collider:
var zoom : int = 10;
var normal : int = 60;
var smooth : float = 5;
private var zoomedIn = false;
function Update () {
if(zoomedIn == true){
ZoomIN();
}
if(zoomedIn == false){
ZoomOUT();
}
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Player"){
zoomedIn = true;
}
}
function OnTriggerExit(other : Collider){
if(other.tag == "Player"){
zoomedIn = false;
}
}
function ZoomIN(){
Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,zoom,Time.deltaTime*smooth);
}
function ZoomOUT(){
Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView,normal,Time.deltaTime*smooth);
}