Monday, June 6, 2022
HomeGame Developmentunity - The way to restrict digital camera rotation angle

unity – The way to restrict digital camera rotation angle


I wish to rotate my digital camera horizontally across the object 360 diploma and wish to restrict my vertical rotation from -45 to 45 levels. I’ve discovered some resolution over web however none of them are work for mouse click on enter. Right here is my working code with out vertical rotation restrict.

[SerializeField]
non-public Digital camera _camera;

[SerializeField]
non-public Remodel goal;

non-public Vector3 previousPosition;



// Begin is named earlier than the primary body replace
void Begin()
{
    
}

//Replace is named as soon as per body
void Replace()
{
    if (Enter.GetMouseButtonDown(0))
    {
        previousPosition = _camera.ScreenToViewportPoint(Enter.mousePosition);
    }

    if (Enter.GetMouseButton(0))
    {
        Vector3 route = previousPosition - _camera.ScreenToViewportPoint(Enter.mousePosition);

        _camera.rework.place = goal.place;

        _camera.rework.Rotate(new Vector3(1, 0, 0), route.y * 180);
        _camera.rework.Rotate(new Vector3(0, 1, 0), -direction.x * 180, Area.World);
        _camera.rework.Translate(new Vector3(0, 0.3f, -3));

        previousPosition = _camera.ScreenToViewportPoint(Enter.mousePosition);


    }

}

If somebody can level me how can I restrict the vertical rotation that may be very useful for me.
Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments