- Home /
Question by
simonsenl2006 · Aug 31, 2020 at 10:33 PM ·
camera
Mouse wont move on axis
I'm trying to learn unity 2020 and just starting off by making the camera move around, the code is as follows:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour { public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0F, 0F);
playerBody.Rotate(Vector3.up * mouseX);
}
} All help appreciated, thanks.
Comment
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
ratchet and clank style camera 0 Answers
Camera lock on enemy 0 Answers
Unity 5.2 camera not recognised 1 Answer
Oblique Frustum Clipping 0 Answers