public override BehaviourStatus OnBehave(BehaviourState state) { BehaviourContext enemyContext = (BehaviourContext)state; if (enemyContext.enemyInSight()) { playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position; } if ((!enemyContext.enemyInRange(0.5f) && !enemyContext.enemyTooClose())) { enemyContext.enemyWeaponController.isFiring = false; return(BehaviourStatus.FAILURE); } if ((!enemyContext.enemyTooClose() && enemyContext.enemyInSight())) { enemyContext.enemyWeaponController.isFiring = false; return(BehaviourStatus.SUCCESS); } ///////////////////////////////////////////////////////////// if (closestNode == null) { closestNode = PathFinder.getRetreatNode(enemyContext.pathNodes, enemyContext.enemyPhysics.transform, playerPosition); } if (PathFinder.atDestination(enemyContext.enemy.transform, closestNode.transform.position)) { closestNode = PathFinder.getRetreatNeighbor(closestNode, enemyContext.enemy.transform, playerPosition); if (closestNode == null) { closestNode = PathFinder.getRetreatNode(enemyContext.pathNodes, enemyContext.enemyPhysics.transform, playerPosition); } } enemyContext.enemyPhysics.enemyRotation(playerPosition); if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle") || enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("attack")) { enemyContext.enemyAnimation.Play("walk"); } enemyContext.enemyPhysics.enemyMovement(closestNode.transform.position, angle); if (!enemyContext.enemyWeaponController.isFiring) { enemyContext.enemyWeaponController.isFiring = true; } //////////////////////////////////////////////////////////////// return(BehaviourStatus.RUNNING); }
//Leaf node that checks whether or not it is directly close to the player to back up. public override BehaviourStatus OnBehave(BehaviourState state) { BehaviourContext enemyContext = (BehaviourContext)state; if (enemyContext.enemyTooClose()) { if (enemyContext.enemySight.enableDebug) { Debug.Log("Player Too Close, Backing UP"); } enemyContext.startNode = null; return(BehaviourStatus.SUCCESS); } return(BehaviourStatus.FAILURE); }
//Leaf node that checks whether or not it is directly close to the player for a ranged attack. public override BehaviourStatus OnBehave(BehaviourState state) { BehaviourContext enemyContext = (BehaviourContext)state; if (enemyContext.enemyInRange(0.0f) && !enemyContext.enemyTooClose()) { if (enemyContext.enemySight.enableDebug) { Debug.Log("Player Can be Shot"); } enemyContext.startNode = null; return(BehaviourStatus.SUCCESS); } return(BehaviourStatus.FAILURE); }
public override BehaviourStatus OnBehave(BehaviourState state) { BehaviourContext enemyContext = (BehaviourContext)state; if (!enemyContext.enemyInRange(0.5f) || !enemyContext.enemyInSight() || enemyContext.enemyTooClose()) { if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("attack")) { enemyContext.enemyAnimation.Play("idle"); } enemyContext.enemyWeaponController.isFiring = false; return(BehaviourStatus.FAILURE); } if (GameObject.FindGameObjectWithTag("Player") != null) { playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position; } else { enemyContext.enemyWeaponController.isFiring = false; return(BehaviourStatus.SUCCESS); } enemyContext.enemyPhysics.enemyRotation(playerPosition); if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle") || enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("walk")) { enemyContext.enemyAnimation.Play("attack"); } if (!enemyContext.enemyWeaponController.isFiring) { enemyContext.enemyWeaponController.isFiring = true; } return(BehaviourStatus.RUNNING); }