예제 #1
0
    void SetPosAndRotByCurCurve()
    {
        if (!GameController.isGamePaused && Time.deltaTime != 0)
        {
            Vector3 interpolatedPoint = curAntaresCurve.GetInterpolatedPoint(curCurveInfoCounter);

            Vector3 destRot = interpolatedPoint - controlledSoldier.position;

            if (IsCurveCounterReachedToEnd())
            {
                Vector3 endInterPoint = curAntaresCurve.GetInterpolatedPoint(curCurveInfoCounter + curveThreshold);
                destRot = endInterPoint - controlledSoldier.position;
            }

            float deltaAngle = Mathf.DeltaAngle(
                MathfPlus.HorizontalAngle(controlledSoldier.forward),
                MathfPlus.HorizontalAngle(destRot));

            float rotAmount = deltaAngle;

            Quaternion rotVec = Quaternion.Euler(0, rotAmount, 0);

            if (!isFirstTickOnCurveInfo)
            {
                controlledSoldier.rotation *= rotVec;
            }

            //controlledSoldier.position = new Vector3(interpolatedPoint.x, controlledSoldier.position.y, interpolatedPoint.z);
            controlledSoldier.position = new Vector3(interpolatedPoint.x, GetGroundY(), interpolatedPoint.z);
        }
    }
예제 #2
0
    public static float GetDeltaAngle(Vector3 _sourceForwardVec, Vector3 _sourcePos, Vector3 _targetPos)
    {
        Vector3 destForwardVec = _targetPos - _sourcePos;
        float   deltaAngle     = Mathf.DeltaAngle(
            MathfPlus.HorizontalAngle(_sourceForwardVec),
            MathfPlus.HorizontalAngle(destForwardVec));

        return(deltaAngle);
    }
예제 #3
0
    //public bool RotateSoldierAllBodyToRotation(Quaternion rot, float rotSpeed, float toleranceAngle)
    //{
    //    Quaternion targRot = rot;
    //    Quaternion soldRot = gameObject.transform.rotation;

    //    Quaternion soldOldRot = gameObject.transform.rotation;

    //    targRot.SetEulerAngles(0, targRot.eulerAngles.y * Mathf.Deg2Rad, 0);
    //    soldRot.SetEulerAngles(0, soldRot.eulerAngles.y * Mathf.Deg2Rad, 0);

    //    soldRot = Quaternion.Slerp(soldRot, targRot, rotSpeed * Time.deltaTime);
    //    gameObject.transform.rotation = soldRot;

    //    return (Quaternion.Angle(soldRot, soldOldRot) <= toleranceAngle);
    //}

    public bool RotateSoldierAllBodyToRotation(Quaternion _rot, float _rotSpeed, float _toleranceAngle)
    {
        Quaternion rot            = _rot;
        float      rotSpeed       = _rotSpeed;
        float      toleranceAngle = _toleranceAngle;

        float maxStartingAngleToDecreaseTotalRotAmount = 30f;
        float minDecreasedRotAmountCoef = 0.3f;

        Vector3 pos = transform.position + rot * Vector3.forward;

        float rotAmount = rotSpeed * Time.deltaTime;

        Vector3 destRot = pos - transform.position;

        float deltaAngle = Mathf.DeltaAngle(
            MathfPlus.HorizontalAngle(transform.forward),
            MathfPlus.HorizontalAngle(destRot));

        if (Mathf.Abs(deltaAngle) < maxStartingAngleToDecreaseTotalRotAmount)
        {
            rotAmount *= (1 - (((maxStartingAngleToDecreaseTotalRotAmount - Mathf.Abs(deltaAngle)) / maxStartingAngleToDecreaseTotalRotAmount) * (1 - minDecreasedRotAmountCoef)));
        }

        if (deltaAngle < 0)
        {
            rotAmount = -rotAmount;
        }

        if (Mathf.Abs(rotAmount) > Mathf.Abs(deltaAngle))
        {
            transform.rotation = rot;
            return(true);
        }

        Quaternion rotVec = Quaternion.Euler(0, rotAmount, 0);

        transform.rotation *= rotVec;
        return(false);


        //float deltaAngle = MathfPlus.GetDeltaAngle(transform.forward, transform.position, pos);

        //if (Mathf.Abs(rotAmount) >= Mathf.Abs(deltaAngle))
        //{
        //    transform.rotation = rot;
        //    return true;
        //}

        //float dif = deltaAngle - currentUpBodyAngle;

        //if (dif >= 0)
        //{
        //    currentUpBodyAngle += rotAmount;
        //}
        //else
        //{
        //    currentUpBodyAngle -= rotAmount;
        //}

        //return false;
    }