Esempio n. 1
0
    public void Sense()
    {
        if (preferClosestTarget)
        {
            GameObject go = sight.GetClosest(transform.position);
            if (go != null)
            {
                target = go.transform;
            }
        }

        if (target == null || !sight.IsVisible(target.gameObject))
        {
            if (sight.perceived.Count > 0)
            {
                if (preferClosestTarget)
                {
                    GameObject go = sight.GetClosest(transform.position);
                    if (go != null)
                    {
                        target = go.transform;
                    }
                }
                else
                {
                    GameObject go = sight.GetRandom();
                    if (go)
                    {
                        target = go.transform;
                    }
                }
            }
            else
            {
                target = null;
            }
        }

        if (target)
        {
            currentPosition = target.position;
            direction       = currentPosition - this.transform.position;
            distance        = direction.magnitude;
            if (distance < aimRange)
            {
                lastKnownPosition = currentPosition;
            }
        }
    }
Esempio n. 2
0
    public void Sense()
    {
        if (player == null || !sensePlayer.IsVisible(player.gameObject))
        {
            if (sensePlayer.perceived.Count > 0)
            {
                player = sensePlayer.GetRandom().transform;
            }
            else
            {
                player = null;
            }
        }

        if (player)
        {
            Vector3 currentPlayerPosition = player.position;
            playerDirection = currentPlayerPosition - this.transform.position;
            distance        = playerDirection.magnitude;
            if (distance < seeDistance)
            {
                lastKnownPlayerPosition = currentPlayerPosition;
            }
        }

        if (friend == null || !senseFriends.IsVisible(friend.gameObject))
        {
            if (senseFriends.perceived.Count > 0)
            {
                try
                {
                    friend = senseFriends.GetClosest(this.transform.position).transform;
                }
                catch (System.Exception)
                { friend = null; }
            }
            else
            {
                friend = null;
            }
        }
    }