Camera rotation on mouse input
Basically I have a camera behind a player and just want to rotate the x,y axis on the equivalent x,y movement of the mouse.
Prob showing my noobness here but why is z changing?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
[SerializeField] private string mouseXInputName, mouseYInputName;
[SerializeField] private float mouseSensitivity;
private void LockCursor()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
CameraRotation();
}
private void CameraRotation()
{
float mouseX = Input.GetAxis(mouseXInputName) * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis(mouseYInputName) * mouseSensitivity * Time.deltaTime;
transform.Rotate(Vector3.left * mouseY);
transform.Rotate(Vector3.up * mouseX);
}
}
A week with unity as been a great experience but I am still really struggling with scripting 3d space.
Maybe its me as I am trying to run before walking, but the above is just static parent camera and even then confused why is Z changing?
If I am going to run then what I am trying to do is :
Have a player follow cam behind the player object that is the player point of view. So when I change the x,y position of the current world view I also pan back smoothly to get the player object in the middle by rotating the position around the player.
So maybe we better start with why is Z changing on my clunky hacked code? Lols wow my head is spinning more than my worldpoint :)