Beispiel #1
0
        // Behaviours

        // PATROL
        void Patrol()
        {
            if (patrolPath == null)
            {
                return;
            }

            timeSinceArrivedAtWaypoint += Time.deltaTime;
            Vector3 nextPosition = originalPosition;

            if (AtWaypoint())
            {
                timeSinceArrivedAtWaypoint = 0f;
                CycleWaypoint();
            }

            nextPosition = GetCurrentWaypoint();

            if (timeSinceArrivedAtWaypoint > waypointDwellTime)
            {
                // MoveTo(nextPosition);
                AI_Helpers.MoveTo(
                    nextPosition,
                    maxSpeed,
                    patrolSpeedFraction,
                    navMeshAgent
                    );
            }

            return;
        }
Beispiel #2
0
        // CHASE
        void Chase()
        {
            Debug.Log("target:::" + target);
            if (target == null)
            {
                return;
            }

            MakeTargetStrafe();

            Vector3 destination     = targetLastKnownPosition;
            float   currentDistance = Vector3.Distance(target.transform.position, transform.position);

            // Has reached target
            if (currentDistance <= stoppingDistanceToPlayer)
            {
                state = AGENT_STATE.FIGHTING;
                return;
            }

            // Player escaped
            if (currentDistance > maxChasingDistance)
            {
                state = AGENT_STATE.PATROL;
                return;
            }

            // Has Stamina To Continue chase?
            if (stamina.HasStaminaAgainstCostAction(staminaChasingCost))
            {
                AI_Helpers.MoveTo(destination, maxSpeed, patrolSpeedFraction, navMeshAgent);

                stamina.DecreaseStamina(staminaChasingCost);
            }
            else
            {
                // Stamina depleted
                return;
            }
        }