public void setWaypoint(double x, double y)
    {
        targetX = x;
        targetY = y;

        double myTheta = state.get(7) % (Math.PI * 2); //my theta, between 0 and 6.28
        if(myTheta < 0) myTheta+= Math.PI * 2.0;
        double yDist = (state.get(1)+scrollY) - targetY; //y and x distance to the waypoint
        double xDist = (state.get(0)+scrollX) - targetX;
        //System.out.print((Math.sqrt((yDist * yDist) + (xDist * xDist))) + " "); 
        if((Math.sqrt((yDist * yDist) + (xDist * xDist)))<30) close = true; //if it hit, stop moving
        else close = false;
        double TTotal = Math.asin(yDist / (Math.sqrt((yDist * yDist) + (xDist * xDist)))); //waypoint's theta relative to origin of ship
        if(xPos+scrollX>x)
        {
            if(TTotal > 0)
            {
                TTotal = -TTotal + Math.PI;
            }
            else TTotal = -TTotal - Math.PI;
        }
        TTotal = -TTotal;
        if(TTotal < 0) TTotal += Math.PI * 2.0;

        toTurn = TTotal - myTheta;
        if(toTurn > Math.PI) 
        {
            toTurn = -(Math.PI * 2.0 - toTurn);

        }
        else if (toTurn < -Math.PI)
        {
            toTurn = (Math.PI * 2.0 + toTurn);
        }

        //speed = Math.min(maxSpeed, maxSpeed * (1-(Math.abs(toTurn) / Math.PI)) * (1-(Math.abs(toTurn) / Math.PI)) * (1-(Math.abs(toTurn) / Math.PI)));
        speed = Math.min(Math.min(maxSpeed, Math.sqrt((yDist * yDist) + (xDist * xDist))/40.0 * (1-(Math.abs(toTurn) / Math.PI)) * (1-(Math.abs(toTurn) / Math.PI)) * (1-(Math.abs(toTurn) / Math.PI))), state.get(6)+0.5);
        //yVel = Math.min(20, Math.sqrt((yDist * yDist) + (xDist * xDist)) * (1-(Math.abs(toTurn) / Math.PI)));

        //System.out.println(speed);
        //System.out.println(targetX + " " + targetY);
        //System.out.println(scrollX + " " + scrollY + " " + xPos + " " + yPos); //(toTurn) / Math.PI + " "+ TTotal / Math.PI + " " + myTheta/Math.PI);
    }