Search Unity

Help with clamping down camera.

Discussion in 'Scripting' started by TianWolf, Sep 4, 2012.

  1. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    How do I limit the up and down motion of a camera that uses game object.rotate ?
     
  2. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    I tried using Mathf.clamp. Which either did nothing or made the camera spin uncontrollably.
     
  3. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    We need more info. how is your camera moving? what exactly are you trying to accomplish(Why do you need the camera clamped)...
     
  4. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    the camera moves using gameObject.rotate, and I'm trying to keep the camera from turning a full 360 along the X-axis.

    Also I played around with the Mathf.clamp a little more and now the camera is locked to the floor.
     
  5. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    I gave up on the Mathf.clamp. I'm using if checks instead. my code looks like this:

    Code (csharp):
    1.  
    2.         if (cameraPivot.rotation.x > .4  camRotation.y > 0)
    3.         {
    4.            
    5.         }
    6.         else if(cameraPivot.rotation.x < -.4  camRotation.y < 0)
    7.         {
    8.            
    9.         }
    10.         else
    11.         {
    12.             cameraPivot.Rotate( camRotation.y, 0, 0 );
    13.         }
    14.  
    This seems to work fine.