Show results
code
using UnityEngine;
using Cinemachine;
public class CameraController : MonoBehaviour
{
private CinemachineFreeLook freeLookCamera;
void Start()
{
freeLookCamera= GetComponent<CinemachineFreeLook>();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButton(0))
{
freeLookCamera.m_XAxis.m_InputAxisValue = Input.GetAxis("Mouse X");
freeLookCamera.m_YAxis.m_InputAxisValue = Input.GetAxis("Mouse Y");
}
else
{
freeLookCamera.m_XAxis.m_InputAxisValue = 0;
freeLookCamera.m_YAxis.m_InputAxisValue = 0;
}
}
}
Steps
1. Select UnityRegistry in Packages in PackageManager, search for Cinemachine and install it
2. Right-click in the Hierarchy window to create a new FreeLookCamera
3.Hang the above script on the newly created camera
FreeLookCamera key parameter function
Follow and LookAt
Follow: The camera follows the moving target, usually the player is selected
LookAt: The point where the camera is looking. You can create an empty object under the player. LookAt is set to this empty object. You can easily adjust the point where the camera is looking.
AxisControl axis control
Y Aixs controls the vertical axis of the camera, and X Aixs controls the horizontal axis.
Value: relative position on the axis, determines the specific position of the camera
Speed: The maximum speed at which the camera turns
Accel Time/Decel Time: The time required for the camera to accelerate to the maximum speed or decelerate to 0. For example, when the Accel Time is set to 10 and the Input Axis Value is 1, the camera's rotation speed gradually accelerates to the maximum speed within 10 seconds.
Input Axis Name: Determines the name of the input of InputAxisValue. The default is Mouse X and Mouse Y. The corresponding name can be adjusted in ProjectSettings->InputManager. Since this article uses code to control input, the name is set to empty.
Input Axis Value: The input on the corresponding axis, the minimum is 0 and the maximum is 1. If the input is between 0 and 1, the camera rotation speed will slow down.
Orbits camera track
When a camera is selected and Gizmos is opened, the camera's track can be seen in the Scene window, and the camera will move on the track.
BindingMode: Binding mode of the camera. Different binding modes will have different tracking effects. The following is the difference between Simple Follow With World Up and World Space.
TopRig, MiddleRig, ButtomRig, adjust the radius and height of the three tracks
It’s not easy to create a blog, please like and follow me~
If there are any inaccuracies, please point them out in the comment area