public void DoActions(StateController_lsy controller) { foreach (AIAction_lsy action in Actions) { action.Act(controller); } }
private void Patrol(StateController_lsy controller) { newDirection = controller.Path.CurrentPoint - controller.transform.position; newDirection = newDirection.normalized; controller.CharacterMovement.SetHorizontal(newDirection.x); controller.CharacterMovement.SetVertical(newDirection.y); }
private bool AttackCompleted(StateController_lsy controller) { if (controller.CharacterWeapon.CurrentWeapon.GetComponentInChildren <Animator>().GetCurrentAnimatorStateInfo(0).length > controller.CharacterWeapon.CurrentWeapon.GetComponentInChildren <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime) { return(true); } return(false); }
private bool CheckTarget(StateController_lsy controller) { targetCollider2D = Physics2D.OverlapCircle(controller.transform.position, detectArea, targetMask); if (targetCollider2D != null) { controller.Target = targetCollider2D.transform; return(true); } return(false); }
private bool PlayerInRangeToAttack(StateController_lsy controller) { if (controller.Target != null) { // Get Distance float distanceToAttack = (controller.Target.position - controller.transform.position).sqrMagnitude; // Compare and return if we are close to the target return(distanceToAttack < Mathf.Pow(minDistanceToAttack, 2)); } return(false); }
private void EvaluateObstacles(StateController_lsy controller) { hit = Physics2D.BoxCast(controller.Collider2D.bounds.center, obstacleBoxCheckSize, 0f, wanderDirection, wanderDirection.magnitude, obstacleMask); if (hit) { // Pick random location wanderDirection.x = Random.Range(-wanderArea, wanderArea); wanderDirection.y = Random.Range(-wanderArea, wanderArea); //// Update wander time //wanderCheckTime = Time.time; } }
private void Wander(StateController_lsy controller) { if (wanderCheckTime <= 0f) { // Pick random location wanderDirection.x = Random.Range(-wanderArea, wanderArea); wanderDirection.y = Random.Range(-wanderArea, wanderArea); // Move our enemy controller.CharacterMovement.SetHorizontal(wanderDirection.x); controller.CharacterMovement.SetVertical(wanderDirection.y); //// Update wander time //wanderCheckTime = Time.time + wanderTime; wanderCheckTime = wanderTime; } }
private void ShootPlayer(StateController_lsy controller) { // Stop enemy controller.CharacterMovement.SetHorizontal(0); controller.CharacterMovement.SetVertical(0); // Shoot if (shootCheckTime <= 0f) { if (controller.CharacterWeapon.CurrentWeapon != null) { //controller.CharacterWeapon.CurrentWeapon.WeaponAim.SetAim(aimDirection); controller.CharacterWeapon.CurrentWeapon.UseWeapon(); shootCheckTime = shootTime; } } }
public void EvaluateTransitions(StateController_lsy controller) { if (Transitions != null || Transitions.Length > 1) { for (int i = 0; i < Transitions.Length; i++) { bool decisionResult = Transitions[i].Decision.Decide(controller); if (decisionResult) { controller.TransitionToState(Transitions[i].TrueState); } else { controller.TransitionToState(Transitions[i].FalseState); } } } }
private void Shoot(StateController_lsy controller) { if (nextShotTime <= 0) { if (controller.PlayerHealth.CurrentHealth >= 7) { controller.BossSpiralPattern.EnableProjectile(); } if (controller.PlayerHealth.CurrentHealth >= 4 && controller.PlayerHealth.CurrentHealth < 7) { controller.BossRandomPattern.EnableProjectile(); } if (controller.PlayerHealth.CurrentHealth < 4) { controller.BossCirclePattern.EnableProjectile(); } nextShotTime = shotDelay; } }
private void FollowTarget(StateController_lsy controller) { if (controller.Target == null) { return; } // Follow Horizontal if (controller.transform.position.x < controller.Target.position.x) { controller.CharacterMovement.SetHorizontal(1); } else { controller.CharacterMovement.SetHorizontal(-1); } // Follow Vertical if (controller.transform.position.y < controller.Target.position.y) { controller.CharacterMovement.SetVertical(1); } else { controller.CharacterMovement.SetVertical(-1); } // Stop if min distance reached (Horizontal) if (Mathf.Abs(controller.transform.position.x - controller.Target.position.x) < minDistanceToFollow) { controller.CharacterMovement.SetHorizontal(0); } // Stop if min distance reached (Vertical) if (Mathf.Abs(controller.transform.position.y - controller.Target.position.y) < minDistanceToFollow) { controller.CharacterMovement.SetVertical(0); } }
public override bool Decide(StateController_lsy controller) { return(AttackCompleted(controller)); }
public override bool Decide(StateController_lsy controller) { return(PlayerInRangeToAttack(controller)); }
public void EvaluateState(StateController_lsy controller) { DoActions(controller); EvaluateTransitions(controller); }
public override void Act(StateController_lsy controller) { FollowTarget(controller); }
public abstract bool Decide(StateController_lsy controller);
public override bool Decide(StateController_lsy controller) { return(CheckTarget(controller)); }
public override void Act(StateController_lsy controller) { nextShotTime -= Time.deltaTime; Shoot(controller); Debug.Log("acting"); }
//private Vector2 aimDirection; public override void Act(StateController_lsy controller) { shootCheckTime -= Time.deltaTime; // DeterminateAim(controller); ShootPlayer(controller); }
public abstract void Act(StateController_lsy controller);
public override void Act(StateController_lsy controller) { Patrol(controller); }
public override void Act(StateController_lsy controller) { wanderCheckTime -= Time.deltaTime; EvaluateObstacles(controller); Wander(controller); }