public void Update() { //Debug.Log(aiController.gameObject.name + ": ReturnState.Update()"); aiController.UpdateTarget(); if (aiController.MyTarget != null && aiController.AggroEnabled() == true) { aiController.ChangeState(new FollowState()); } float distanceToLeashPosition = Vector3.Distance(aiController.MyLeashPosition, aiController.MyBaseCharacter.CharacterUnit.transform.position); //Debug.Log(aiController.gameObject.name + ": ReturnState: Distance from spawn point: " + distance.ToString()); if (distanceToLeashPosition <= 1) { aiController.ChangeState(new IdleState()); } else { float agentDestinationDrift = Vector3.Distance(aiController.MyLeashPosition, aiController.MyBaseCharacter.AnimatedUnit.MyAgent.destination); if (agentDestinationDrift >= aiController.MyBaseCharacter.AnimatedUnit.MyAgent.stoppingDistance + aiController.MyBaseCharacter.AnimatedUnit.MyCharacterMotor.MyNavMeshDistancePadding) { //Debug.Log("ReturnState.Update(). agent destination is: " + aiController.MyBaseCharacter.MyAnimatedUnit.MyAgent.destination + "; resetting to: " + aiController.MyStartPosition); this.aiController.SetDestination(aiController.MyLeashPosition); } } }
public void Update() { //Debug.Log(aiController.gameObject.name + ": AttackState.Update()"); aiController.UpdateTarget(); if (aiController.MyTarget != null) { aiController.MyBaseCharacter.MyCharacterUnit.MyCharacterMotor.FaceTarget(aiController.MyTarget); if (!aiController.IsTargetInHitBox(aiController.MyTarget)) { // target is out of range, follow it aiController.ChangeState(new FollowState()); } else { // target is in range, attack it if (aiController.MyBaseCharacter.MyCharacterCombat.MyWaitingForAutoAttack == false) { // we were getting too much spam in logs from just passing this through rather than waiting until it was a valid action aiController.AttackCombatTarget(); } } // check range and attack } else { //Debug.Log(aiController.gameObject.name + ": about to change to returnstate"); aiController.ChangeState(new ReturnState()); } }
public void Update() { //Debug.Log(aiController.gameObject.name + ": IdleState.Update()"); aiController.UpdateTarget(); // change into follow state if the player is close if (aiController.MyTarget != null) { aiController.ChangeState(new FollowState()); } }
public void Update() { //Debug.Log(aiController.gameObject.name + ": AttackState.Update()"); aiController.UpdateTarget(); if (aiController.MyTarget == null) { //Debug.Log(aiController.gameObject.name + ": about to change to returnstate"); aiController.ChangeState(new ReturnState()); return; } if (aiController.MyBaseCharacter.MyCharacterAbilityManager.MyWaitingForAnimatedAbility == true) { //Debug.Log(aiController.gameObject.name + ".AttackState.Update() MyWaitingForAnimatedAbility is true"); // nothing to do, animated ability in progress return; } if (aiController.MyBaseCharacter.MyCharacterCombat.MyWaitingForAutoAttack == true) { //Debug.Log(aiController.gameObject.name + ".AttackState.Update() MyWaitingForAutoAttack == true"); // nothing to do, auto-attack in progress return; } if (aiController.MyBaseCharacter.MyCharacterAbilityManager.MyIsCasting == true || aiController.MyBaseCharacter.MyCharacterAbilityManager.MyCurrentCastCoroutine != null) { //Debug.Log(aiController.gameObject.name + ".AttackState.Update() MyCurrentCast != null || MyIsCasting == true"); // nothing to do, cast in progress return; } // face target before attack to ensure they are in the hitbox aiController.MyBaseCharacter.MyAnimatedUnit.MyCharacterMotor.FaceTarget(aiController.MyTarget); if (aiController.CanGetValidAttack(true)) { return; } // no valid ability found, try auto attack range check if (!aiController.IsTargetInHitBox(aiController.MyTarget)) { // target is out of range, follow it aiController.ChangeState(new FollowState()); return; } // target is in range, attack it //aiController.AttackCombatTarget(); }
private void MakeFollowDecision() { aiController.UpdateTarget(); if (aiController.MyTarget != null) { //Debug.Log("current agro range is " + parent.MyAggroRange.ToString() + " and current distance to target is " + parent.MyDistanceToTarget); // evade if the target is out of aggro range. In the future this could also be calculated as distance from start point if we would rather use a leash approach // temporarily disable leashing. /* * if (Vector3.Distance(aiController.transform.position, aiController.MyStartPosition) > aiController.MyLeashDistance ) { * aiController.ChangeState(new EvadeState()); * return; * } */ /* * if (aiController.MyDistanceToTarget > aiController.MyAggroRange) { * aiController.ChangeState(new EvadeState()); * return; * } */ if (aiController.CanGetValidAttack()) { aiController.ChangeState(new AttackState()); return; } if (aiController.IsTargetInHitBox(aiController.MyTarget)) { // they are in the hitbox and we can attack them aiController.ChangeState(new AttackState()); } else { //Debug.Log(aiController.gameObject.name + ": FollowTarget: " + aiController.MyTarget.name); // if within agro distance but out of hitbox range, move toward target if (aiController.HasMeleeAttack() || (aiController.GetMinAttackRange() > 0f && (aiController.GetMinAttackRange() < aiController.MyDistanceToTarget))) { aiController.FollowTarget(aiController.MyTarget, aiController.GetMinAttackRange()); } else { aiController.MyBaseCharacter.AnimatedUnit.MyCharacterMotor.StopFollowingTarget(); } } } else { // there is no target so start idling. should we return to our start position instead? aiController.ChangeState(new ReturnState()); } }
public void Update() { //Debug.Log(aiController.gameObject.name + ": IdleState.Update()"); aiController.UpdateTarget(); // change into follow state if the player is close if (aiController.MyTarget != null && aiController.AggroEnabled() == true) { //Debug.Log(aiController.gameObject.name + ": IdleState.Update(): setting follow state"); aiController.ChangeState(new FollowState()); return; } TryToEnterPatrolState(); }
public void Update() { //Debug.Log(aiController.gameObject.name + ": FollowState.Update()"); aiController.UpdateTarget(); if (aiController.MyTarget != null) { //Debug.Log("current agro range is " + parent.MyAggroRange.ToString() + " and current distance to target is " + parent.MyDistanceToTarget); // evade if the target is out of aggro range. In the future this could also be calculated as distance from start point if we would rather use a leash approach // temporarily disable leashing. /* * if (Vector3.Distance(aiController.transform.position, aiController.MyStartPosition) > aiController.MyLeashDistance ) { * aiController.ChangeState(new EvadeState()); * return; * } */ /* * if (aiController.MyDistanceToTarget > aiController.MyAggroRange) { * aiController.ChangeState(new EvadeState()); * return; * } */ if (aiController.IsTargetInHitBox(aiController.MyTarget)) { // they are in the hitbox and we can attack them aiController.ChangeState(new AttackState()); } else { //Debug.Log(aiController.gameObject.name + ": FollowTarget: " + aiController.MyTarget.name); // if within agro distance but out of hitbox range, move toward target aiController.FollowTarget(aiController.MyTarget); } } else { // there is no target so start idling. should we return to our start position instead? aiController.ChangeState(new ReturnState()); } }
public void Update() { //Debug.Log(aiController.gameObject.name + ": PatrolState.Update() at location: " + aiController.transform.position); aiController.UpdateTarget(); if (aiController.MyTarget != null) { aiController.MyLeashPosition = aiController.MyBaseCharacter.MyCharacterUnit.transform.position; aiController.ChangeState(new FollowState()); } if (Vector3.Distance(aiController.MyBaseCharacter.MyCharacterUnit.transform.position, currentDestination) <= aiController.MyBaseCharacter.MyCharacterUnit.MyAgent.stoppingDistance + aiController.MyBaseCharacter.MyCharacterUnit.MyCharacterMotor.MyNavMeshDistancePadding) { //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): Destination Reached!"); currentDestination = aiController.MyAiPatrol.GetDestination(true); // destination reached if (aiController.MyAiPatrol.PatrolComplete()) { if (aiController.MyAiPatrol.MyDespawnOnCompletion) { aiController.MyBaseCharacter.MyCharacterUnit.Despawn(0, false, true); } else { aiController.ChangeState(new IdleState()); } } else { //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): Destination Reached and patrol not complete yet!"); coroutine = (aiController as MonoBehaviour).StartCoroutine(PauseForNextDestination(currentDestination)); this.aiController.MyBaseCharacter.MyCharacterUnit.MyCharacterMotor.MyMovementSpeed = this.aiController.MyMovementSpeed; } } }
public void Update() { //Debug.Log(aiController.gameObject.name + ": PatrolState.Update() at location: " + aiController.transform.position); if (aiController.MyAiPatrol.enabled == false) { aiController.ChangeState(new IdleState()); return; } aiController.UpdateTarget(); if (aiController.MyTarget != null) { aiController.MyLeashPosition = aiController.MyBaseCharacter.MyCharacterUnit.transform.position; aiController.ChangeState(new FollowState()); } bool getNewDestination = false; if (currentDestination == Vector3.zero && coroutine == null) { getNewDestination = true; } else if (Vector3.Distance(aiController.MyBaseCharacter.MyCharacterUnit.transform.position, currentDestination) <= aiController.MyBaseCharacter.MyAnimatedUnit.MyAgent.stoppingDistance + aiController.MyBaseCharacter.MyAnimatedUnit.MyCharacterMotor.MyNavMeshDistancePadding) { //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): Destination Reached!"); // destination reached if (aiController.MyAiPatrol.PatrolComplete()) { if (aiController.MyAiPatrol.MyDespawnOnCompletion) { if (aiController.MyBaseCharacter.MyCharacterUnit != null) { aiController.MyBaseCharacter.MyCharacterUnit.Despawn(0, false, true); } } else { aiController.ChangeState(new IdleState()); return; } } else { //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): Destination Reached and patrol not complete yet!"); getNewDestination = true; } } //pathstatus: " + animatedUnit.MyAgent.pathStatus if (aiController.MyBaseCharacter.MyAnimatedUnit.MyAgent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathInvalid) { // this message means things are working properly and the unit just prevented itself from getting stuck or stalling //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): DESTINATION WAS INVALID, GETTING NEW DESTINATION"); getNewDestination = true; } if (aiController.MyBaseCharacter.MyAnimatedUnit.MyAgent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathPartial) { // this message means things are working properly and the unit just prevented itself from getting stuck or stalling //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): DESTINATION WAS PARTIAL, GETTING NEW DESTINATION"); getNewDestination = true; } if (getNewDestination == true) { Vector3 tmpDestination = aiController.MyAiPatrol.GetDestination(true); if (tmpDestination == Vector3.zero) { //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): GOT ZERO DESTINATION, SKIPPING TO NEXT UPDATE"); return; } // destination is safe, set it currentDestination = tmpDestination; this.aiController.MyBaseCharacter.MyAnimatedUnit.MyCharacterMotor.MyMovementSpeed = this.aiController.MyMovementSpeed; coroutine = (aiController as MonoBehaviour).StartCoroutine(PauseForNextDestination(currentDestination)); } }