- Home /
Smooth transition from Camera1 to Camera2?
I have this piece of code before Start()
 //Sets the current camerastate to true (default is Third-Person)
 private bool Camerastate = true;
And this piece of code in Update()
 //Sets camerastate to the Third-Person when true, and First-Person when false
         if(Camerastate == true)
         {
             ThirdPerson.enabled = true;
             FirstPerson.enabled = false;
         }
 
         else 
         {
             ThirdPerson.enabled = false;
             FirstPerson.enabled = true;
         }
 
         //Sets the Camerastate to the opposite of the current Camerastate
         if(Input.GetKeyDown(KeyCode.Tab))
         {
             Camerastate = !Camerastate;
 
         }
It works very well but I was wondering how I could make the transition more smooth. I don't need any Crossfade effects or Checkerboards or something, but I just want the view to make a certain, smooth motion from the Third-Person view and the First-Person view. I want it to do something like in this video, where the starting point is where Camera one is, and the end point where Camera is. --> Time in video: See 5:56 to 6:01) Thanks a lot guys!!!
Answer by luminance · May 17, 2014 at 06:11 PM
You want to Slerp the position and rotation of the camera from one position to another, something like this:
 float timer = 0f;
 void Update()
 {
     timer += Time.deltaTime
     if(timer <= 1f)
     {
         camera.position = Vector3.Slerp(camera.position, targetPosition, timer);
         camera.rotation = Vector3.Slerp(camera.rotation, targetRotation, timer);
     }
 }
You'll need to define what the target position is, and you might want the move to take longer than 1 second, but that's the gist of what you want.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                