// Seek using Steering mode. private void Seek(EnemyStateController controller, Vector3 targetpoint) { // Check for target dist from arrival radius Vector3 direction = targetpoint - controller.transform.position; // Vector3 direction = controller.nav_agent.steeringTarget - controller.transform.position; float distance = (direction).magnitude; if (distance < controller.enemy_stats.arrival_radius) { controller.current_vel = Vector3.zero; controller.current_accel = Vector3.zero; return; } //Set accel controller.current_accel += direction.normalized * (controller.enemy_stats.maximum_acceleration) * Time.deltaTime; //cap accel if (controller.current_accel.magnitude > controller.enemy_stats.maximum_acceleration) { controller.current_accel.Normalize(); controller.current_accel *= controller.enemy_stats.maximum_acceleration; } controller.current_vel += (controller.current_accel * Time.deltaTime); //cap vel if (controller.current_vel.magnitude > controller.enemy_stats.maximum_velocity) { controller.current_vel.Normalize(); controller.current_vel *= controller.enemy_stats.maximum_velocity; } Vector3 newpos = controller.transform.position + (controller.current_vel * Time.deltaTime); controller.transform.position = newpos; }
private void DoActions(EnemyStateController controller) { for (int i = 0; i < actions.Length; i++) { actions[i].Act(controller); } }
private EnemyState CheckTransitions(EnemyStateController enemy) { // Find player. PlayerController player = (PlayerController)enemy.GetData <PlayerController>(StateData.Player); //GameObject.FindGameObjectWithTag(Tags.Player).GetRequiredComponent<PlayerController>(); for (int transitionIndex = 0; transitionIndex < m_Transitions.Length; transitionIndex++) { EnemyState nextState; if (m_Transitions[transitionIndex].CheckTransition(enemy, player)) { nextState = m_Transitions[transitionIndex].GetTrueState; } else { nextState = m_Transitions[transitionIndex].GetFalseState; } if (nextState != null) { return(nextState); } } return(null); }
public override void StateEnter() { detectCollider = enemy.transform.Find("DetectCollider").GetComponent <Collider2D>(); stateController = enemy.GetComponent <EnemyStateController>(); // Debug.Log("Looking for the enemy"); lastTurn = stateController.timePatrolling; }
private void SetupAI() { //get enemy state controller stateController = GetComponent <EnemyStateController>(); //SetFlyHeightFromGround(flyHeight); aiActive = true; stateController.SetupStateController(this); rb.constraints = RigidbodyConstraints.FreezeRotation; //so darkling know where to return this.startTransform = new SaveTransform(this.transform); //assign type for darkling switch (darklingType) { case DarklingType.Idle: stateController.currentState = darklingIdleStartState; break; case DarklingType.Wander: stateController.currentState = darklingWanderStartState; break; //if not assign, leave it there default: break; } }
// Initialization function for a state public void InitState(EnemyStateController controller) { for (int i = 0; i < actions.Length; i++) { actions[i].Init(controller); } }
public override bool Decide(EnemyStateController controller) { DarklingAirEnemy darkling = (DarklingAirEnemy)controller.enemy; bool isTargetInZone = detectTarget(darkling); return(isTargetInZone); }
void Start() { audioSource = GetComponent <AudioSource>(); stateController = transform.parent.GetComponent <EnemyStateController>(); detectCollider = GetComponent <Collider2D>(); enemyCollider = transform.parent.GetComponent <Collider2D>(); Physics2D.IgnoreCollision(detectCollider, enemyCollider, true); }
public override void StateEnter() { stateController = enemy.GetComponent <EnemyStateController>(); bullet = stateController.bullet; player = stateController.detectedPlayer; lastAttack = stateController.reactionTime; Debug.Log("Got you, ya son of a bitch!"); }
public override bool Decide(EnemyStateController controller) { SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy; bool targetDetected = Scan(skeleton); return(targetDetected); }
public override void Act(EnemyStateController controller) { //simple cast SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy; //move Attack(skeleton); }
private void DoActions(EnemyStateController controller) { // Loop through all actions associated with this state. for (int i = 0; i < actions.Length; i++) { // Do actions. actions[i].Act(controller); } }
private void moveToStartPosition(EnemyStateController controller) { Vector3 targetLocation = controller.StartLocation; Vector3 newPosition = controller.transform.position; Vector3 dir = (targetLocation - newPosition).normalized; controller.transform.position = newPosition + dir * controller.Stats.MoveSpeed * Time.fixedDeltaTime; controller.transform.up = dir; }
/* * called by EnemyStateController, when transition to new state */ public void OnExitState(EnemyStateController controller) { if (exitAction == null) { return; } exitAction.Act(controller); }
private bool Scan(EnemyStateController controller) { // Vector3 tempScanPos = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)); controller.agent.isStopped = true; // controller.transform.Translate(controller.transform.position + tempScanPos * controller.enemyStats.moveSpeed * Time.deltaTime); return(controller.CheckIfTimeElapsed(controller.enemyStats.searchDuration)); }
private void MoveTowardsPlayer(EnemyStateController controller) { Vector3 newPosition = controller.transform.position; Vector3 dir = (controller.HeroTransform.position - newPosition).normalized; newPosition = newPosition + (dir * controller.Stats.MoveSpeed * Time.fixedDeltaTime); controller.transform.position = newPosition; controller.transform.up = dir; }
// Start is called before the first frame update void Start() { gettingSucked = false; Vector3 suckInfo = lookup.ContainsKey(enemyType) ? lookup[enemyType] : lookup["default"]; suckRate = suckInfo.x; suckLeft = suckInfo.y; suckDamage = suckInfo.z; state = gameObject.GetComponent <EnemyStateController>(); }
private void Patrol(EnemyStateController controller) { // controller.enemyAnim.SetTrigger("Walk"); controller.agent.destination = controller.wayPointsList[controller.nextWayPoint].position; controller.agent.isStopped = false; if (controller.agent.remainingDistance <= controller.agent.stoppingDistance && !controller.agent.pathPending) { controller.nextWayPoint = (controller.nextWayPoint + 1) % controller.wayPointsList.Count; } }
private bool closeToLocation(EnemyStateController controller) { Vector3 myPosition = controller.transform.position; Vector3 distance = controller.StartLocation - myPosition; if (distance.magnitude <= .5f) { return(true); } return(false); }
public override bool Decide(EnemyStateController controller) { DarklingAirEnemy darkling = (DarklingAirEnemy)controller.enemy; if (darkling.isCloseEnoughToTarget(darkling.startTransform.position, 1)) { return(true); } return(false); }
public override bool Decide(EnemyStateController controller) { SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy; if (skeleton.isCloseEnoughToTarget(skeleton.startTransform.position, 1)) { return(true); } return(false); }
public void UpdateState(EnemyStateController enemy, EnemyStateController.StateCallback stateCallback) { UpdateStateLogic(enemy); // Check whether the state can transition to the next state. EnemyState nextState = CheckTransitions(enemy); if ((stateCallback != null) && (nextState != null)) { stateCallback(nextState); } }
private void Patrol(EnemyStateController controller) { controller.NavAgent.Resume(); if (controller.NavAgent.path.reachedDestination) { controller.NavAgent.waypointIndex = (controller.NavAgent.waypointIndex + 1) % controller.NavAgent.waypoints.waypoints.Count; controller.NavAgent.NextWaypoint(); } controller.SetWaypointLocation(); }
private void Suck(EnemyStateController controller) { bool playerLooking = controller.IsSeen(); if (playerLooking) { Vector3 newPos = controller.HeroTransform.position; Vector3 dir = controller.transform.position - newPos; controller.Hero.GetComponent <Rigidbody2D>().AddForce(dir.normalized * 375f, ForceMode2D.Force); } }
protected override void UpdateStateLogic(EnemyStateController enemy) { PlayerController player = (PlayerController)enemy.GetData <PlayerController>(StateData.Player); // Move towards the next player position. enemy.GetNavMeshAgent.destination = player.gameObject.transform.position; enemy.GetNavMeshAgent.isStopped = false; if (enemy.GetEnemyController.GetAnimator.IsAnimating == false) { enemy.GetEnemyController.GetAnimator.WalkForward(); } }
public override bool Decide(EnemyStateController controller) { DarklingAirEnemy darkling = (DarklingAirEnemy)controller.enemy; bool attackAgain = false; if (darkling.target != null && darkling.hasDoneAttacking) { attackAgain = true; } return(attackAgain); }
public override void Act(EnemyStateController controller) { SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy; //simple check if (skeleton.patrolPositions.Length == 0) { return; } //move Patrol(skeleton); }
public override void Act(EnemyStateController controller) { // Debug.Log("CHASE STATE"); // Chase the player Vector2 chaseVector = Vector2.MoveTowards( controller.transform.position, controller.enemyMovementController.chaseTarget.position, Time.deltaTime * 5.0f); controller.transform.position = new Vector3( chaseVector.x, controller.transform.position.y, controller.transform.position.z); }
private GameObject IsEnemyNearPlayer(EnemyStateController enemy) { // Get a list of colliders within the given radius of the enemy. Collider[] colliderList = Physics.OverlapSphere(enemy.GetEnemyController.transform.position, m_DistanceFromPlayer, Layers.GetLayerMask(Layers.Player)); // In theory, the player should be the only thing on the player layer, so if the list is greater than 0, the player is within that radius. if (colliderList.Length > 0) { return(colliderList[0].gameObject); } else { return(null); } }
public bool CheckTransition(EnemyStateController enemy, PlayerController player) { // For this transition to return true, all the decisions in the list must return true (&& relationship). for (int decisionIndex = 0; decisionIndex < m_Decisions.Length; decisionIndex++) { if (m_Decisions[decisionIndex].Decide(enemy, player) == false) { // Decision failed, transition can not be transitioned. return(false); } } // All the decisions were successful! Transition is a-go! return(true); }