Hello! My name is Nicky – I run the channel iHeartGamedev over on youtube. I’ve made some in-depth tutorials over the past year covering Cinemachine and how amazing it is. My most recent video covered the Free Look Camera:
I’m currently attempting to recreate Mario’s camera system in Super Mario Odyssey and my analysis has brought me to the conclusion that we can recreate it with two separate “Free Look Cameras”. The main camera uses “Simple Follow with World Up” and the second uses “Lock To Target on Assign” to transition into a top down effect.
I have two issues that I’m trying to work through and I think that they are both bugs.
Using “inherit position” this setup works pretty well! The problem that I’m running into is that when the transition occurs, there is a single frame where the camera is in its previous position. Please see the following Gfycat where I step through each frame.
Frame by Frame:
reasonableunfitfennecfox
In Motion:
elaborateremarkableeelelephant
This happens in all orbit settings outside of “Simple Follow With World Up”. I’m uncertain if it’s occurring because of inherit position or something more specific to the orbit setting. But ideally when we transition from the “Simple Follow With World Up” camera to the “Lock to Target on Assign”, the camera has already moved to the correct position.
The second issue that I am having is related to the State Driven Camera. I’ve created two separate behaviors for each of these states (TopDown and ThirdPerson). In order to transition from one state to the other, we are check the Y Axis value and the Input Value Gain. If the conditions are met, we’ll switch to the other state.
My question here is related to getting a reference to the active camera. Ideally, we can do this in the OnEnterState method of the behavior by accessing the Cinemachine brain. That code looks something like this:
CinemachineStateDrivenCamera _stateCam;
CinemachineFreeLook _freeLookCam;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
_stateCam = Camera.main.GetComponent<CinemachineBrain>().ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineStateDrivenCamera>();
_freeLookCam = _stateCam.LiveChild.VirtualCameraGameObject.GetComponent<CinemachineFreeLook>();
}
However, I noticed that the brain is out-of-sync with the animator’s state machine. If we transition from one state to the other using animator.Play("TopDown")
, the live camera of the Cinemachine State Driven cam will still be the “ThirdPerson” cam in the OnStateEnter
method of the “TopDown”'s behavior.
I’ve gotten around this by checking the !_stateCam.IsLiveChild(_freeLookCam)
in the OnStateUpdate
method… but that is definitely not a good practice and I feel like the Brain should be updated by the time OnEnterState
is called so that we can just get the reference there.
Is there a better way to get the reference to the camera that is associated with each state and state behavior of the State Driven Camera?
Appreciate the help in advance!