public override NodeState Evaluate() { if (firstTime) { agent.isStopped = false; anim.SetBool("isMoving", true); enemy = (Transform)blackboard.GetValue("currentEnemy"); if (enemy == null) { return(NodeState.FAIL); } Vector3 positionToGo = NavMeshUtilities.SamplePositionNearMe(transform.position, enemy.position); agent.SetDestination(positionToGo); firstTime = false; } else { if (enemy == null) { return(NodeState.FAIL); } } if (imNearTheEnemy()) { return(NodeState.SUCCESS); } if (timer >= timeBetweenDestinations) { agent.SetDestination(enemy.position); timer = 0f; } timer += Time.deltaTime; return(NodeState.RUNNING); }
public override void OnStateEnter() { base.OnStateEnter(); Vector3 currentEnemyBase = (Vector3)globalBlackboard.GetValue("currentEnemyBase"); Vector3 positionToGo = NavMeshUtilities.SamplePositionNearMe(transform.position, currentEnemyBase); agent.SetDestination(positionToGo); }
public override void OnStateEnter() { agent.isStopped = false; anim.SetBool("isMoving", true); Vector3 homeLocation = (Vector3)globalBlackboard.GetValue("baseLocation"); Vector3 positionToGo = NavMeshUtilities.SamplePositionNearMe(transform.position, homeLocation); agent.SetDestination(positionToGo); base.OnStateEnter(); }
public override NodeState Evaluate() { Vector3 baseLocation = (Vector3)globalBlackboard.GetValue("baseLocation"); if (baseLocation != agent.destination) { agent.SetDestination(NavMeshUtilities.SamplePositionNearMe(transform.position, baseLocation)); agent.isStopped = false; anim.SetBool("isMoving", true); } if (agent.remainingDistance <= distanceHome && !agent.pathPending) { agent.isStopped = true; anim.SetBool("isMoving", false); return(NodeState.SUCCESS); } return(NodeState.RUNNING); }