Hey, I use the following script to control the camera with the mouse:
[SerializeField] private float sensX;
[SerializeField] private float sensY;
[SerializeField] private Transform orientation;
private float yRotation;
private float xRotation;
public static CameraLook Instance;
private void Awake()
{
Instance = this;
}
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
if (Typewriter.Instance.IsWriting())
return;
Vector2 input = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
float mouseX = input.x * Time.fixedDeltaTime * sensX;
float mouseY = input.y * Time.fixedDeltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
How would I add a method with a target transform & rotation speed as input, lock the camera, slerp it until it aims at the target and resume input? I tried it many times but every time it resets back to the position it started from.
Thanks for the help!