Пример #1
0
    public Vector3 Pursue(CharController target)
    {
        Vector3 distanceToTarget = target.transform.position - transform.position;
        float   relativeHeading  = Vector3.Dot(forwardVector, target.GetForwardVector());

        //If difference in direction is less that 18 degrees, simply head towards the target
        if ((Vector3.Dot(forwardVector, distanceToTarget) > 0) && (relativeHeading > 0.9))
        {
            return(Seek(target.transform.position));
        }
        else
        {
            //Calculate seconds ahead to predict
            float predictionTime = distanceToTarget.magnitude / (maxSpeed + PlayerInfo.Instance.MaxSpeed());
            //Head towards targets current heading
            return(Seek(target.transform.position + target.GetVelocityVector() * predictionTime));
        }
    }