- Home /
 
How to animate zooming in of the camera?
I would like to achieve the zooming in of a camera like aim down a sniper scope over time. Here is my current script.
class FieldsOfView { var narrow : float; var wide : float; } var fieldsOfView : FieldsOfView;
 
               var delay : float;
 
               function Update () { if (Input.GetKeyDown("f")) { StartCoroutine(ChangeFieldOfView()); enabled = false; } 
}
  
               function ChangeFieldOfView () { yield WaitForSeconds(delay); camera.fieldOfView = camera.fieldOfView == fieldsOfView.narrow ? fieldsOfView.wide : fieldsOfView.narrow; enabled = true;  
} 
Answer by Velketor · Mar 30, 2011 at 12:36 PM
It's easier to animate your sniper using Unity's Animation Timeline
Shawn
How to animate fieldOfView in Animation timeline ? Details please 
Answer by demize2010 · Mar 30, 2011 at 12:49 PM
You probably want to have a shot with the Lerp function:
http://unity3d.com/support/documentation/ScriptReference/Mathf.Lerp.html
I've used this recently to control the field of view to get a similar effect.
EDIT
For example you could try:
camera.fieldOfView = (Mathf.Lerp(fieldsOfView.narrow, fieldsOfView.wide, Time.time), 0, 0);
 
              Answer by Cyb3rManiak · May 08, 2011 at 12:09 PM
Try this...
var fZoomDuration: float = 1.0; // This determines how fast the zoom will be. Lower values mean faster animation. var fOneOverDurationToZoom: float = 1.0 / fZoomDuration;
 
               var fStartValue: float = camera.fieldOfView; var fEndValue: float = camera.fieldOfView == fieldsOfView.narrow ? fieldsOfView.wide : fieldsOfView.narrow;
 
               var fTime: float = 0.0; var fLerp: float = 0.0;
 
               while (fLerp <= 1f) { fLerp = fTime * fOneOverDurationToZoom; camera.fieldOfView = Mathf.Lerp(fStartValue, fEndValue, fLerp); fTime += Time.deltaTime; yield; } 
 
              Answer by OusedGames · Jul 04, 2017 at 01:46 AM
Just watch this tutorial! Hope it works.. @DevonJS 
 https://www.youtube.com/watch?v=0cWvJEokGsw 
Your answer
 
             Follow this Question
Related Questions
Change field of view over time 1 Answer
Camera movement in a 2D? (like angry birds) 1 Answer
Find out if GameObject is in Field of View 2 Answers
Negative results when converting HFOV to VFOV? 1 Answer
Automatically adjust cameras FOV to maintain a perfect 360 coverage with multiple cameras 0 Answers