- Home /
activating a camera animation?
In my main menu, i want to be able to click on something and have the camera fly out, but i have no idea how to do that. if you could, please show me a script and explain what to do.
Answer by Sarus · Mar 06, 2012 at 02:27 PM
Your question is pretty vague so I'm not entirely sure what you want to do. However, in general, to move the camera around via an animation my suggestion to is to install iTween from the asset store then use the valueTo() method to tween the camera from its current location to where you want it to go. Add the below two methods to a script that is attached to your camera. Then call animateCamera() and pass in the current location of the camera and the location you want the camera to move to.
/*
* Callback function that is called by iTween during each
* update(). newPosition is the position of the camera that
* is between the fromPosition and the toPosition
*/
private void moveCameraUpdate(Vector3 newPosition){
camera.transform.position = newPosition;
}
/*
* This method will animate the camera over 1 second from
* the fromPosition to the toPosition.
*/
private void animateCamera(Vector3 fromPosition, Vector3 toPosition){
iTween.ValueTo(this.gameObject, iTween.Hash("time", 1f, //how long you want the animation to last
"delay", 0f, //delay before the animation starts
"from", fromPosition, //start position of your camera
"to", toPosition, //end position of your camera
"onupdate", "moveCameraUpdate", //callback function that is called for each step of tween
"easetype", iTween.EaseType.easeInOutExpo //easing function
));
Note that this is C# code so it'll have to go into a C# script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064242im_/https://answers.unity.com/themes/thub/images/avi.jpg)