I am making a gravity controlled camera, but i need it to only turn only 90 degrees on a condition.

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 ):

Please use code tags: https://discussions.unity.com/t/481379

I’ve never heard of a “gravity controlled camera” so perhaps you want to work through a few Youtube tutorials that seem to do with what you’re attempting to accomplish.

If you run into trouble, here is how to report problems productively in the Unity3D forums:

http://plbm.com/?p=220

1 Like

I am sorry, that I even asked, because after sleeping I think i have a solution. So now i feel shame for asking and wasting people time, thanks Kurt-Dekker for your patience and helping me understand mistakes that i made :slight_smile:

1 Like