- Home /
The question is answered, right answer was accepted
How can I smoothly transition my player camera from manual control into an animation?
I'm trying to create an inventory system in which the player takes off their backpack and looks into it. I have the basic animation set up, but I am having trouble smoothly transitioning from the player being able to look around freely to the camera being forced to look into the backpack. When I update the camera's rotation in the Update function, even when the animation is not playing, the camera is clamped in the starting rotation for the animation and the player cannot look around. If I change it so that the camera updates in the LateUpdate function, then I can rotate the camera but when I start playing the animation, the camera instantly snaps to the starting position. I would like to achieve an effect where the player would be able to look around but as soon as they press the inventory button, the camera cross-fades from its current rotation into the animation. Sorry if what I am saying isn't clear and thanks for any help.
P.S. I know how I could do this through scripting by just rotating the camera to the starting position and then playing the animation, but I want to achieve a more fluid and dynamic effect and not increase the total time it takes to access the backpack.
P.S.S. I already have code in place that stops the player from walking and looking around when they press the inventory button.
Answer by instruct9r · Oct 04, 2015 at 11:05 AM
I woud parent one GameObject to the player, position it, to the same place, where the camera is and animate it to make the transition from that position to the backpack...
Then when you press the inventory button i woud Lerp the camera from the current position to the position of that GameObject and at the same time, start the animation of the, GameObject to transition.
Same when you get out of the inventory. Keep the camera follow the GameObject, while going back and when it reaches the old position i woud turn off the Lerp.
This way you can have camera to be moved with script (When following the player) and to move with actual animated object, when going to the backpack.
You can turn the Lerp On\Off with one boolean...