Beispiel #1
0
    public static RESULT Rotate(float currentAngleY, float targetAngleY, float speed, float arriveThreshold)
    {
        float dAngle = targetAngleY - currentAngleY;

        dAngle = AngleHelper.LimitAngleInNPI_PI(dAngle);

        float turnLimitAngle = speed * TimeHelper.deltaTime;
        float cAngle         = 0;

        if (dAngle > 0)
        {
            cAngle = Mathf.Min(turnLimitAngle, dAngle);
        }
        else if (dAngle < 0)
        {
            cAngle = Mathf.Max(-turnLimitAngle, dAngle);
        }

        float leftDegree = AngleHelper.LimitAngleInNPI_PI(dAngle - cAngle);

        RESULT r = new RESULT();

        r.arrived           = Mathf.Abs(leftDegree) <= arriveThreshold;
        r.turnDegree        = cAngle;
        r.leftDegree        = leftDegree;
        r.destinationAngleY = currentAngleY + cAngle;
        return(r);
    }
Beispiel #2
0
    public static float CalcRotationTo(Vector3 a, Vector3 b, float currentAngleY)
    {
        float targetAngle = CalcRotationAngleY(a, b);

        float dAngle = (targetAngle - currentAngleY);

        dAngle = AngleHelper.LimitAngleInNPI_PI(dAngle);
        return(dAngle);
    }