Advertisement
Guest User

MouseMovement

a guest
Nov 27th, 2022
31,337
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 1 0
  1. public class MouseMovement : MonoBehaviour
  2. {
  3.  
  4.     public float mouseSensitivity = 100f;
  5.  
  6.     float xRotation = 0f;
  7.     float YRotation = 0f;
  8.  
  9.     void Start()
  10.     {
  11.       //Locking the cursor to the middle of the screen and making it invisible
  12.       Cursor.lockState = CursorLockMode.Locked;
  13.     }
  14.  
  15.     void Update()
  16.     {
  17.        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
  18.        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
  19.  
  20.        //control rotation around x axis (Look up and down)
  21.        xRotation -= mouseY;
  22.  
  23.        //we clamp the rotation so we cant Over-rotate (like in real life)
  24.        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
  25.  
  26.        //control rotation around y axis (Look up and down)
  27.        YRotation += mouseX;
  28.  
  29.        //applying both rotations
  30.        transform.localRotation = Quaternion.Euler(xRotation, YRotation, 0f);
  31.  
  32.     }
  33. }
  34.  
Advertisement
Comments
  • LightBlueGaming
    1 year (edited)
    # C# 0.29 KB | 0 0
    1. what have i do wrong, if i wanna add the script to my player pop there a window up:
    2.  
    3. Can't add script
    4.  
    5. Can't add script component 'movement' because the script dass cannot be found. Make Sure that there are no compilor errors and that the file name and class name match.
    6.  
    7.  can anyone help me?
Add Comment
Please, Sign In to add comment
Advertisement