I`m a literally a NEW game maker and I wanted to make a (“drone”) that you could drive walls and see where your player is. I would like to know how to rotate another object to the same side as my mouse goes when controlling the camera. BTW i need the object to rotate only 90 degrees. (the object is just the drone, I actually don’t know how to control it too, but if it rotates only 90 degrees it will not be hard). Plus i wanted to ask: does anyone know how to limit the x axis rotation(adopt the y axis limitation to work on x too.)
I don’t know am i asking to much, but i am literally stuck.
THE CODE OF cameraRotatingScript:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
private void Start()
{
//gravity = Physics.gravity;
Cursor.lockState = CursorLockMode.Locked;
}
public enum RotationAxis
{
MouseX = 1,
MouseY = 2
}
public RotationAxis axes = RotationAxis.MouseX;
public float minimumVert = -45.0f;
public float maximumVert = 45.0f;
public float sensHorizontal = 10.0f;
public float sensVertical = 10.0f;
public float _rotationX = 0;
// Update is called once per frame
void Update()
{
if (axes == RotationAxis.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensHorizontal, 0);
}
else if (axes == RotationAxis.MouseY)
{
_rotationX -= Input.GetAxis("Mouse Y") * sensVertical;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert); //Clamps the vertical angle within the min and max limits (45 degrees)
float rotationY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
}
if (Input.GetKeyDown("escape"))
{
Cursor.lockState = CursorLockMode.None;
}
}
}
I hope someone helps cause if not idk what I will do ):