How would I implement a system like Hollow Knight or Sonic 1 where the player can look up by holding the Up Arrow key and look down by holding the Down Arrow key? I know that it would need the following:
public Cinemachine vCam;
//to move the camera
void Update()
{
Input.GetAxisRaw("Vertical");
//to get the input required
}
I am using CinemachineConfiner2D and have a Virtual Camera attached to my player character. I could not find any tutorials online on how to do this, so replying would be greatly appreciated.
Duplicate the Virtual Camera that’s following your character and give it a positive Y offset so that it’s looking above your character. Also give it a lower Priority value than your current character-following Virtual Camera.
You can then throw in some basic logic that says:
if (Up Arrow is pressed)
{
upwardsCamera.Priority = 10;
defaultCamera.Priority = 1;
}
else
{
defaultCamera.Priority = 10;
upwardsCamera.Priority = 1;
}
(Where upwardsCamera
and defaultCamera
reference their respective CinemachineVirtualCamera
s).
The Virtual Camera with the highest priority is the one that is transitioned to. You can also specify the default transition type and duration via the CinemachineBrain component, which should be located on the Main Camera by default.
It’s also worth noting that you can achieve the same exact thing by simply enabling/disabling Virtual Cameras. So if you’d like, you could rework the logic to say “if ‘Up Arrow’ is pressed, enable upwardsCamera
and disable defaultCamera
; else, vice versa.”