Going to share the approach I’m using in having a 3rd person controller using Cinemachine Virtual Camera controlling it using mobile Input.
YouTube: https://youtu.be/88855QY4CXk
GitHub: https://github.com/rehtse-studio/Cinemachine_MobileInput
Starter Assets — Third Person Character Controller: https://assetstore.unity.com/packages/essentials/starter-assets-third-person-character-controller-196526
What do we have on this project?
On the Hierarchy I have a the Player GameObject called PlayerWithVirtualCamera, on it you will find components like the Animator, SphereCollider and a Rigidbody; it is also hold the script called PlayerControllerWithVirtualCamera . I also have the PlayerInput component that will allows me to use the Input Actions called VCamera3rdPersonInputActions from Unity’s New Input System.
The VirtualCamera_UI GameObject hold two UI Canvas: UI_Standard and UI_Mobile
UI_Standard canvas hold the buttons to make the effect that I’m turning the Mobile Input ON or OFF.
UI_Mobile canvas has the necessary UI GameObject that hold the Mobile Input logics. A UI Panel called LookTouchPanel hold the script UITouchPanel that will create the necessary value X and Y to control the camera on mobile.
A UI Image called JoystickContainer has a script that create the X and Y value to move the player, the script is called UIVirtualJoystick
There is another UI Image named RunAction that has the On-ScreenButton script from the new Input System and it will behave like a GamePad LeftTrigger establish by the Control Path.
Inside the players GameObject I’m holding the Cinemachine Virtual Camera and a empty GameObject CameraTargetObject. The CameraTargetObject is the LookAt and the Follow of the CinemachineVirtualCamera that will allow me from the script to rotate; this empty game object is near the chest area of the player.
Scripts
PlayerControllerWithVirtualCamera
On the script I have the necessary variables and reference to control my player and to get the inputs from the virtual joystick, the touch panel and from the new Input System.
UIVirtualJoystick
- NOTE: The logic for the Joystick was studying using Unity’s New Asset that has different mobile environment for Input*
UITouchPanel
At the beginning of the article you have links for the Unity project and the video from YouTube.
Hope it helps.
To be continued 😎