public void followWaypoint()
    {

        if(!close)
        {
            setWaypoint(targetX + (scrollX - state.get(9)), targetY + (scrollY - state.get(10))); //calculate speed and direction to waypoint (same as last turn)
            double eachTurn; //turn this frame is a fraction of the total turn
            if(toTurn>0)
            {
                eachTurn = Math.min(toTurn, maxTheta);
            }
            else eachTurn = Math.max(-maxTheta, toTurn); //limit by maximum theta
            if(state.get(8)>=0 && eachTurn<=0 || state.get(8)<=0 && eachTurn>=0)
            {
                setTurn(eachTurn);
            }
            else setTurn(0);

        }
        else 
        {
            state.set(2, 0.0);
            state.set(3, 0.0);
            setTurn(0);
        }
    }