Does anyone know why this is not rotating locally on the Y axis?
When the drone is on its side, moving my mouse up and down still rotates it globally:
When the drone is on its side, moving my mouse up and down still rotates it globally
Diagram of what I am trying to achieve:
Diagram of what I am trying to achieve
Current script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Look : MonoBehaviour
{
public float mouseSensitivity = 2.5f;
public float ADrotatDegree = 1f;
private float xRotat = 0f;
private float yRotat = 0f;
private float zRotat = 0f;
public Transform playerBody;
void Start()
{
// Lock the mouse cursor to the game screen.
Cursor.lockState = CursorLockMode.Locked;
}
void Update(){
if(Time.timeScale != 0) {
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
xRotat -= mouseY;
zRotat -= mouseX;
playerBody.localRotation = Quaternion.Euler(xRotat, yRotat, zRotat);
}
}
void FixedUpdate()
{
if (Input.GetKey(KeyCode.A)) yRotat -= ADrotatDegree;
if (Input.GetKey(KeyCode.D)) yRotat += ADrotatDegree;
}
}
I am new and very much a script kiddie so feel free to send full scripts :)