- Home /
Smoothly move camera Field of View upon Trigger
I'd like to smoothly adjust the camera position between the original position and field of view to a new one upon a trigger and back again when exiting the trigger area.
How would I approach this, i'm a newb at this? Could someone construct a sample script for me to learn?
Check out iTween, and use $$anonymous$$oveAdd from iTween
I've looked into it and have it installed. I feel it's too complicated for me at the moment but do see its value. I will have to spend some time learning how to incorporate this. Unless you could give me an example on how to use it with the code I posted below on neoncraze's comment.
Example code
void OnTriggerEnter(Collider Collider) {
iTween.$$anonymous$$oveAdd(GameObject.Find("Game Object Name"), new Vector3(0, 0, 0), 1);
}
Answer by neoncraze · Nov 18, 2013 at 08:16 AM
I have actually tried to do this for a project of mine and I'd suggest you look at using some of the Vector3 functions, Vector3.SmoothDamp and Vector3.Lerp, to damp/lerp your camera between positions. It works for me and should work fine for what you plan to accomplish, too. It'll be easily transferable too as you'd be able to just have variables to store the Vector3 positions of where ever you want to move your camera to.
I tried this but it doesn't do anything. I think it's something stupid I'm missing. It's a gameObject not attached to anything at the moment:
#pragma strict
var zoomOut: int = 95;
var normal : int = 60;
var smooth : float = 5;
private var poisoned = false;
function update () {
if (poisoned == true){
Camera.main.fieldOfView = $$anonymous$$athf.Lerp(Camera.main.fieldOfView,zoomOut,Time.deltaTime*smooth);
}
else{
Camera.main.fieldOfView = $$anonymous$$athf.Lerp(Camera.main.fieldOfView,normal,Time.deltaTime*smooth);
}
}
function OnTriggerEnter(other : Collider) {
if (other.gameObject.name.StartsWith("Player")) { //Check that we are dealing with the player.
poisoned = true;
}
}
function OnTriggerExit (other : Collider) {
poisoned = false;
}
Your "update" function needs to have the first letter CAPITALIZED
[SOLVED]
Answer by UniqueMindsGroup · Oct 11, 2014 at 04:01 AM
Your "update" function needs to have the first letter CAPITALIZED [SOLVED]
Your answer
Follow this Question
Related Questions
Is there a way to set the horizontal field of view of a camera? 3 Answers
Setting a cube to be exactly size of intersecting camera view plane 1 Answer
How do I set a child object to not rotate if the parent WILL be rotating? 1 Answer
Transform.LookAt - wrong vector 4 Answers
Why is my Camera rotation tilted after parenting it to head? 1 Answer