public override void Execute() { entity.Move(entity.target.position - entity.transform.position, entity.chaseSpeed); if (Time.time > timeToCheck) { if (entity.LookForTarget() == false) { // Enter seach state. EnemySearchState newState = new EnemySearchState(lastTargetPosition + entity.transform.forward * 2.0f, entity.target.position - lastTargetPosition); entity.stateMachine.ChangeState(newState); } else { if (Vector3.Distance(entity.transform.position, entity.target.position) < entity.attackRange - entity.controller.radius) { EnemyAttackState newState = new EnemyAttackState(); entity.stateMachine.ChangeState(newState); } else { lastTargetPosition = entity.target.position; timeToCheck = Time.time + 0.2f; // Check with more frecuency, because the enemy is chasing. } } } }
public void Kill() { IsDead = true; Rigidbody.velocity = Vector2.zero; Rigidbody.isKinematic = true; Collider.enabled = false; AttackState = EnemyAttackState.Approaching; AttackTimeInState = 0; DamagedEffectObject.Ref()?.SetActive(false); IdleSound.Ref()?.Stop(); DieSound.Ref()?.Play(); if (DeathEffectPrefab != null) { Instantiate(DeathEffectPrefab, transform.position, transform.rotation, CoreUtils.GetWorldRoot()); } StartCoroutine(CoHideModel()); if (GrantScore > 0) { //TODO 1P/2P handling, we would need to pass the bullet or HitInfo in ITakeDamage like RpgGame and add a property to BulletScript for which player fired or something GameState.Instance.Player1Score += GrantScore; } }
private void SetEnemyAttackState(EnemyAttackState attackState) { if (attackState == _enemyAttackState) { return; } _enemyAttackState = attackState; }
private static EnemyAttackState _instance; //only declared once private EnemyAttackState() //set instance to itself { if (_instance != null) { return; } _instance = this; }
private void Awake() { //Initialise StateMachine = new EnemyStateMachine(); IdleState = new EnemyIdleState(this, StateMachine, enemyData, "idle"); MoveState = new EnemyMoveState(this, StateMachine, enemyData, "move"); AttackState = new EnemyAttackState(this, StateMachine, enemyData, "inAttack"); DeathState = new EnemyDeathState(this, StateMachine, enemyData, "isDead"); }
private void MakeFSM() { mFSMSystem = new EnemyFSMSystem(); EnemyChaseState chaseState = new EnemyChaseState(mFSMSystem, this); chaseState.AddTransition(EnemyTransition.CanAttack, EnemyStateID.Attack); EnemyAttackState attackState = new EnemyAttackState(mFSMSystem, this); attackState.AddTransition(EnemyTransition.LostSoldier, EnemyStateID.Chase); mFSMSystem.AddState(chaseState, attackState); }
protected virtual void MakeFSM() { fsmSystem = new EnemySatateSystem(); EnemyChaseState chase = new EnemyChaseState(fsmSystem, this); chase.AddTransition(EnemyTransition.CanAttack, EnemyStateID.Attack); fsmSystem.AddState(chase); EnemyAttackState attack = new EnemyAttackState(fsmSystem, this); attack.AddTransition(EnemyTransition.LostSoldier, EnemyStateID.Chase); fsmSystem.AddState(attack); }
private void Init() { if (!this.isInit) { this.isInit = true; this.currentTarget = GameManager.Instance.GetPlayerTransform(); this.moveState = this.gameObject.AddComponent <EnemyMoveState>(); this.attackState = this.gameObject.AddComponent <EnemyAttackState>(); this.ownTransform = this.gameObject.transform; this.moveState.ExitState(); this.attackState.ExitState(); } }
private void MakeFsm() { Fsm = new EnemyFSMSystem(); EnemyChaseState chase = new EnemyChaseState(Fsm, this); chase.AddTransition(EnemyTransition.CanAttack, EnemyStateID.Attack); EnemyAttackState attack = new EnemyAttackState(Fsm, this); attack.AddTransition(EnemyTransition.LostSoldier, EnemyStateID.Chase); Fsm.AddState(chase, attack); }
public void Kill() { IsDead = true; Rigidbody.velocity = Vector2.zero; Rigidbody.isKinematic = true; Collider.enabled = false; AttackState = EnemyAttackState.Approaching; AttackTimeInState = 0; Animator.Ref()?.Play("Die"); DieSound.Ref()?.Play(); if (GrantScore > 0) { //TODO 1P/2P handling, we would need to pass the bullet or HitInfo in ITakeDamage like RpgGame and add a property to BulletScript for which player fired or something GameState.Instance.Player1Score += GrantScore; } }
private void HandleAttack() { if (!CanAttack || IsDead || IsCrashing) { return; } if (!ApproachDone && AttackState != EnemyAttackState.Approaching) { AttackState = EnemyAttackState.Approaching; AttackTimeInState = 0; BulletsFiredInBurst = 0; } if (ApproachDone && AttackState == EnemyAttackState.Approaching) { AttackState = EnemyAttackState.Waiting; } if (AttackState != EnemyAttackState.Approaching) { switch (AttackState) { case EnemyAttackState.WarmingUp: if (AttackTimeInState > AttackWarmup) { //enter fire state AttackState = EnemyAttackState.Firing; AttackTimeInState = 0; } break; case EnemyAttackState.Firing: { AttackSound.Ref()?.Play(); DoAttack(); unchecked { BulletsFiredInBurst++; } //immediately exit, at least for now AttackState = EnemyAttackState.Waiting; AttackTimeInState = 0; } break; case EnemyAttackState.Waiting: if (((BulletBurstCount <= 1 || BulletsFiredInBurst < BulletBurstCount) && AttackTimeInState > AttackInterval)) { //enter fire state AttackState = EnemyAttackState.Firing; AttackTimeInState = 0; if (BulletsFiredInBurst >= BulletBurstCount) { BulletsFiredInBurst = 0; } } break; } AttackTimeInState += Time.deltaTime; } }
public void DoAttack() { state = EnemyAttackState.Dive; camera = Camera.main; }
void Awake() { patrolBehavior = new EnemyStationaryPatrolState(gameObject); attackBehavior = new EnemyAttackState(gameObject); currentState = patrolBehavior; }