Search Unity

Camera Gets Stuck At Corners

Discussion in 'Scripting' started by JollyJenkins, Sep 14, 2012.

  1. JollyJenkins

    JollyJenkins

    Joined:
    Jul 21, 2011
    Posts:
    68
    I've written code for a camera that turns itself from one point to the other in a loop, switching its direction when it hits the corners. The problem I'm having is that every now and then the camera gets jammed at a corners, and spasms out, it can't decide if it should get left or right.

    function camerapatrol() {


    if (transform.rotation.eulerAngles.y < ((axis - viewrange) ) || transform.rotation.eulerAngles.y > ((axis + viewrange) )){
    direction = (direction*-1);

    }

    transform.Rotate (0, (50*Time.deltaTime)*direction, 0);



    }

    Does anyone have a solution to this error by any chance? I would really appreciate the help.