Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Limit camera rotation with RotateAround

Discussion in 'Scripting' started by Danz0r77, Apr 15, 2013.

  1. Danz0r77

    Danz0r77

    Joined:
    Mar 19, 2013
    Posts:
    20
    Hi

    I'm struggling to find the right way to go about this. I think I'm down the wrong alley.
    What I want is for my camera to rotate left and right (while left and right arrow keys are down).

    This works OK:

    Code (csharp):
    1. if (Input.GetKey(KeyCode.LeftArrow)) {
    2.         transform.RotateAround(centerPoint.position,Vector3(0,-1,0),20 * Time.deltaTime);
    3.     }
    I want to limit the max angles that can be reached though. 30 degrees either way. I'm not sure what the best way to go about that is. From what I've read I think RotateAround maybe isn't the way to do it, I need the effect that function gives though - I.E translating the movement at the same time to keep the focus in the center.

    So, what would be the best way of achieving this?

    Thanks
     
unityunity