예제 #1
0
파일: AIMovement.cs 프로젝트: kyranitar/gaf
    bool FollowClosestFriend(int length)
    {
        // Find closest ally (removed if closest ally is self).
        Transform  nearestAllyPos;
        TeamTarget target = gameObject.GetComponent <TargetMarker>().AlliedTargets;

        GameObject nearestAlly = target.FindNearestTarget(this.transform.position);

        if (nearestAlly != null)
        {
            nearestAllyPos = nearestAlly.transform;
        }
        else
        {
            return(false);
        }

        // Make sure ally is not self.
        if (nearestAllyPos == transform)
        {
            nearestAllyPos = null;
        }

        // Let the decision tree know if we found friend or not.
        if (nearestAllyPos)
        {
            SetMoveTarget(nearestAllyPos, false);
            LockAi(length);
            return(true);
        }
        else
        {
            return(false);
        }
    }
예제 #2
0
파일: AIMovement.cs 프로젝트: kyranitar/gaf
    bool FollowClosestEnemy(int length, float maxDist, bool mustBeInFront, bool attack)
    {
        // Find closest enemy (removed if closest enemy is self).
        Transform  nearestEnemyPos;
        TeamTarget target = gameObject.GetComponent <TargetMarker>().EnemyTargets;

        // Try and find any enemy in the game.
        GameObject nearestEnemy = target.FindNearestTarget(this.transform.position);

        if (nearestEnemy != null)
        {
            nearestEnemyPos = nearestEnemy.transform;
        }
        else
        {
            return(false);
        }

        // Make sure ally is not self.
        if (nearestEnemyPos == transform)
        {
            nearestEnemyPos = null;
        }

        // Drop enemy if further away than the maximum distance.
        if (maxDist > 0 && nearestEnemyPos)
        {
            if (Vector3.Distance(nearestEnemyPos.position, transform.position) > maxDist)
            {
                return(false);
            }
        }

        if (mustBeInFront && nearestEnemyPos)
        {
            Vector3 targetDir    = nearestEnemyPos.position - transform.position;
            float   angleBetween = Vector3.Angle(transform.forward, targetDir);
            float   offset       = 0;
            if (angleBetween > 0 - inFrontAngle * 0.5 + offset && angleBetween < inFrontAngle * 0.5 + offset)
            {
            }
            else
            {
                return(false);
            }
        }

        // Let the decision tree know if we found enemy or not.
        if (nearestEnemyPos)
        {
            SetMoveTarget(nearestEnemyPos.transform, attack);
            LockAi(length);
            if (debugActions)
            {
                Debug.Log("I am following " + nearestEnemyPos.name + " at: " + nearestEnemyPos.position);
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }