// OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); //Check if there is a visible object with this aspect & proceed to chase if (visibleTarget != null) { //Set destination to visible target if (astar.goalPos.position != visibleTarget.transform.position) { astar.goalPos.position = visibleTarget.transform.position; //astar.ChangeGoalPosition(visibleTarget.transform.position); } //Target visible & shoot range reached if (astar.reachedGoal) { //Transition to Shoot State animator.SetBool("InShootRange", true); } } else if (visibleTarget == null && !astar.reachedGoal) { //Transition to Last Known Position State animator.SetBool("EnemyLost", true); } else { //Transition to SetWayPoint(Patrol) animator.SetBool("WayPointReached", true); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); if (visibleTarget != null) { //Set destination to visible target if (astar.goalPos.position != visibleTarget.transform.position) { astar.ChangeGoalPosition(visibleTarget.transform.position); } currentTime += Time.deltaTime; if (currentTime >= MaxTime) { currentTime = 0; FireProjectile(animator); Debug.Log("Fire!"); } TurnToTarget(animator, visibleTarget, GovFSM); } else { //Transition to LastKnownPosition animator.SetBool("InShootRange", false); animator.SetBool("EnemyLost", true); astar.isStopped = false;//deactivate astar } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { GovFSM = animator.GetComponent <GovForceFSM>(); astar = animator.GetComponent <AStarNavigation>(); astar.stopRadius = astar.initialstopRadius;//set to the original stopRadius visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); if (visibleTarget != null) { //Transition to Chase animator.SetBool("EnemyLost", false); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); if (visibleTarget != null) { //Transition to chase animator.SetBool("EnemyLost", false); } else if (astar.reachedGoal) { animator.SetBool("WayPointReached", true); } }
// OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); if (visibleTarget != null) { //Transition to Chase Enemy animator.SetBool("EnemyLost", false); } else if (animator.GetBool("WayPointReached")) { astar.ChangeGoalPosition(astar.goalPos.GetComponent <GovWayPoint>().GetRandomDestination()); //Transition to Patrol animator.SetBool("WayPointReached", false); } }
/// <summary> /// Check if Enemy's in sight or if this object reached last known position /// </summary> /// <param name="_animator"></param> private void EnemyFoundCheck(Animator _animator) { visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); if (visibleTarget != null) { //Transition to Chasing //_animator.SetBool("EnemyLost", false); _animator.SetBool("InShootRange", true); } else if (astar.reachedGoal) { //Transition to Patrol _animator.SetBool("WayPointReached", true); } }
// OnStateEnter is called before OnStateEnter is called on any state inside this state machine override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animator.SetBool("EnemyLost", false); astar = animator.GetComponent <AStarNavigation>(); GovFSM = animator.GetComponent <GovForceFSM>(); //set stopping distance to shooting stop distance astar.stopRadius = GovFSM.startShootingRange; visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); //Check if there is a visible object with this aspect & proceed to chase if (visibleTarget != null) { astar.ChangeGoalPosition(visibleTarget.transform.position); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //set enemy not lost animator.SetBool("EnemyLost", false); GovFSM = animator.GetComponent <GovForceFSM>(); astar = animator.GetComponent <AStarNavigation>(); astar.isStopped = true;//activate astar ResetShootTimer(GovFSM); visibleTarget = GovFSM.GetFirstVisibleObject(GovFSM.EnemyAspects); if (visibleTarget != null) { TurnToTarget(animator, visibleTarget, GovFSM); FireProjectile(animator); } else { //Transition to LastKnownPosition animator.SetBool("InShootRange", false); astar.isStopped = false;//deactivate astar } }