Ejemplo n.º 1
0
        public override void Dispatch()
        {
            // If player is out of range, chase him
            bool isFarAwayFromPlayer = Vector3.Distance(context.transform.position, context.target.transform.position) > context.safeDistanceFromTarget;

            if (isFarAwayFromPlayer)
            {
                context.SetState(AGENT_STATE.PATROL);
                return;
            }

            timer += Time.deltaTime;

            if (timer >= timeUntilWeCalculateNextDestination)
            {
                timer = 0;

                if (Vector3.Distance(context.transform.position, context.target.transform.position) >= MINIUMUM_DISTANCE_FROM_TARGET)
                {
                    return;
                }

                // If we are still close to player, reset destination to a further away one
                destination = context.transform.position - context.target.transform.position;
                context.MoveTo(destination);
            }
        }