@Rick_Davidson
@sampattuzzi
@Brian_Trotter
So I said when I implemented a rotating camera, I would come back and post it here…
Go to Cinemachine and add a free look camera.
Add the free look camera to your Core prefab (or camera prefab if you have one, here you can see I disabled my old follow camera from this lecture and now use the free look)
Make sure your fee look camera has a higher priority than anything else… like maybe 100 or something, and set your follow and look at to the Player
…and make sure to tag the camera “PlayerFramingCamera” for the below scripts I will share.
I have suggested settings below… to learn more about what these do watch this vid
I suggest these settings, invert x an y axes as desired…
open the rig settings and scroll down to the bottom rig and apply this suggested setting
finally put the following script on your player prefab…
CameraController.cs
using UnityEngine;
using Cinemachine;
using RPG.Control;
namespace RPG.Core
{
public class CameraController : MonoBehaviour
{
[SerializeField] GameObject freeLookCamera;
CinemachineFreeLook donkey;
PlayerController playerControllerScript;
private void Awake()
{
donkey = freeLookCamera.GetComponent<CinemachineFreeLook>();
playerControllerScript = GetComponent<PlayerController>();
}
private void Update()
{
if (Input.GetMouseButtonDown(1))
{
if (playerControllerScript.isDraggingUI) return;
// use the following line for mouse control of zoom instead of mouse wheel
// be sure to change Input Axis Name on the Y axis to Mouse Y
//donkey.m_YAxis.m_MaxSpeed = 10;
donkey.m_XAxis.m_MaxSpeed = 500;
}
if (Input.GetMouseButtonUp(1))
{
// use the following line for mouse control of zoom instead of mouse wheel
// be sure to change Input Axis Name on the Y axis to Mouse Y
//donkey.m_YAxis.m_MaxSpeed = 0;
donkey.m_XAxis.m_MaxSpeed = 0;
}
// wheel zoom //
// comment out if using mouse control for zoom
if (Input.mouseScrollDelta.y != 0)
{
donkey.m_YAxis.m_MaxSpeed = 10;
}
}
}
}
and drag the free look camera into the script
Two things about adding this…
- This setup is to retain left mouse for actions / right mouse to rotate camera… if you want to change this, these are the scripts you will need to edit… replacing GetMouseButtonDown(0) (be sure to replace the mouse button in the camera controller accordingly)
- That last script CameraFacing will break, so replace the code with this…
CameraFacing.cs
using UnityEngine;
using Cinemachine;
namespace RPG.Core
{
public class CameraFacing : MonoBehaviour
{
[SerializeField] CinemachineFreeLook playerFramingCamera;
private void Start()
{
playerFramingCamera = GameObject.FindGameObjectWithTag("PlayerFramingCamera").GetComponent<CinemachineFreeLook>();
}
void LateUpdate()
{
transform.LookAt(2 * transform.position - playerFramingCamera.transform.position);
}
}
}
and BOOM… You’re a Rock Star. Or at least your player will be… you can zoom RIGHT DOWN in there and admire all your lovely art and see far off in the distance, or scroll up and get a grand bird’s eye view of ALL the action and lots of environment…
Have fun tweaking this.