3rd Person Controller Using Cinemachine Virtual Camera On Mobile

3rd Person Controller Using Cinemachine Virtual Camera On Mobile

·

2 min read

Let me share my approach in having a 3rd Person Character Controller using Cinemachine FreeLook Camera with mobile Input.

[YouTube] https://youtu.be/mqC2XXKkcMg

[GitHub] https://github.com/rehtse-studio/Cinemachine_MobileInput

I’m not going into detail to explain how the UI (FreeLookCamera_UI) works since is the same one I used in my previous article.

The PlayerWithFreeLookCamera object has the script called PlayerControllerWithFreeLookCamera and the PlayerInput component form the New Input system.

The PlayerControllerWithFreeLookCamera script has two key differences in the inspector from the last article. This script only has a reference for the Joystick Input from my UI joystick, in the last article I needed reference to both the look input joystick and empty GameObject called CameraTargetObject inside my player that was doing the rotation

What is the difference?

The difference is that this time I am not using a Virtual Camera, I’m using Cinemachine FreeLook Camera. The FreeLookCamera, that is inside my player, comes right out of the box and has a 3rd person camera view. The FreeLook Camera will Follow my Player’s GameObject and is using the empty game object inside my player to be “Look At”, without it it goes crazy.

Inside the Players Controller Script

PlayerControllerWithFreeLookCamera script has the same code from the last article, the only key difference is that I do not need to tell in code how the camera will move or at what point it need to stop on the rotation since that is done in the Freelook Camera Rigs, the only thing you need to do is to calculate the players movement depending on the rotation or the forward of the camera.

Passing My Look Input To The Free Look Camera

In order to make my Free Look Camera move acording to my touch input on the screen, I need to create a new script call CinemachineMobileInputFeeder

The CinemachineMobileInputFeed is the one taking the look input reference from my UI touch panel. Using Cinemachine namespace I have access to overwrite where the FreeLookCamera get the input.

At the beginning of the article you have links for the Unity project and the video from YouTube.

Hope it helps.

To be continued 😎