public SearchInFrenzyState(HeliScript helicopter, float deltaTime, PursuitState comingFrom, HelicopterState afterLosing) { Debug.Log("Searching"); //Initializing default, independent vals for behavioral variables this.helicopter = helicopter; this.comingFrom = comingFrom; goBackToPursuit = false; ifLost = afterLosing; //Interacting with the frenzy controller frenzy = GameObject.Find("FrenzyController").GetComponent <FrenzyMode>(); rootPos = frenzy.getLastKnownPlayerPosition(); rootPos.y += helicopter.vertDistanceFromPlayerInChase; //Getting the actual player we're chasing down player = GameObject.Find("Player"); lastSeenToRight = player.transform.position.x > rootPos.x; targetPosition = rootPos + new Vector3(searchDist, 0, 0); targetSpotlightRotation = helicopter.getSpotlight().transform.rotation; //These two variables are never updated during pursuit state currSpeed = helicopter.speed * helicopter.frenzySpeedBonus; spotlightRotationSpeed = helicopter.spotlightRotationSpeedChase; //Updates to be ready for the first frame updateState(deltaTime); }
private void InitializeFSM() { // Create Minion FSM. fsm = new FSM <States>(); IdleState <States> idleState = new IdleState <States>(fsm, this); SearchState <States> searchState = new SearchState <States>(fsm, this); FlockState <States> flockState = new FlockState <States>(fsm, this, _flockingEntity); PursuitState <States> pursuitState = new PursuitState <States>(fsm, this); FleeState <States> fleeState = new FleeState <States>(fsm, this); // [EVERYONE] Idle Transitions. idleState.AddTransition(States.FLOCKING, flockState); idleState.AddTransition(States.SEARCHING, searchState); idleState.AddTransition(States.PURSUIT, pursuitState); pursuitState.AddTransition(States.FLEE, fleeState); pursuitState.AddTransition(States.FLOCKING, flockState); pursuitState.AddTransition(States.IDLE, idleState); fleeState.AddTransition(States.IDLE, idleState); fleeState.AddTransition(States.PURSUIT, pursuitState); // [BOSS] Search Transitions. searchState.AddTransition(States.IDLE, idleState); searchState.AddTransition(States.PURSUIT, pursuitState); // [MINIONS] Flocking Transitions. flockState.AddTransition(States.IDLE, idleState); flockState.AddTransition(States.PURSUIT, pursuitState); fsm.SetInitState(idleState); }
public override StateMachine CreateMachine() { AbstractState idle = new IdleState((int)States.DEFAULT, this); AbstractState seek = new SeekState((int)States.SEEK, this); AbstractState pursuit = new PursuitState((int)States.PURSUIT, this); SeekStateMachine stateMachine = new SeekStateMachine(); stateMachine.AddDefaultState(idle); stateMachine.AddState(seek); stateMachine.AddState(pursuit); return stateMachine; }
private void Awake() { wanderState = new WanderState (this); // huntStart = new HuntState (this); May replace with this idleState = new IdleState (this); // huntStart = new HuntState (this); May replace with this forageState = new ForageState (this); flightState = new FlightState (this); pursuitState = new PursuitState (this); exitState = new ExitState (this); enterState = new EnterState (this); navMeshAgent = GetComponent<NavMeshAgent>(); navMeshAgent.enabled = true; // navMeshObstacle.enabled = false; navMeshRadius = navMeshAgent.radius; navMeshAgent.avoidancePriority = Random.Range(0, 100); // Randomly set the avoidance priority }
// Use this for initialization void Start() { attackInfo = GetComponent <AttackInfoContainer> (); attackInfo.attackType = AttackType.MeleeWeakAttack; attackInfo.direction = -transform.up.normalized; attackInfo.force = baseAttackForce; //Get reference of player player = GameObject.Find("Player"); rb = GetComponent <Rigidbody2D> (); //Starting state spiderState = SpiderState.Roaming; pState = PursuitState.Chasing; waitTimer = startWaitTime; projectileTimer = 0f; //targetSpot = Random.Range (0, moveSpots.Length); targetSpot = 0; //first spot }
//配置状态机 private void ConfigFSM() { states = new List <FSMState>(); IdleState idle = new IdleState(); idle.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead); idle.AddMap(FSMTriggerID.SawTarget, FSMStateID.Pursuit); states.Add(idle); DeadState dead = new DeadState(); states.Add(dead); PursuitState pursuit = new PursuitState(); pursuit.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead); pursuit.AddMap(FSMTriggerID.ReachTarget, FSMStateID.Attacking); pursuit.AddMap(FSMTriggerID.LoseTarget, FSMStateID.Default); states.Add(pursuit); AttackingState attacking = new AttackingState(); attacking.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead); attacking.AddMap(FSMTriggerID.WithoutAttackRange, FSMStateID.Pursuit); attacking.AddMap(FSMTriggerID.KilledTarget, FSMStateID.Default); states.Add(attacking); PatrollingState patrolling = new PatrollingState(); patrolling.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead); patrolling.AddMap(FSMTriggerID.SawTarget, FSMStateID.Pursuit); patrolling.AddMap(FSMTriggerID.CompletePatrol, FSMStateID.Idle); states.Add(patrolling); }
protected virtual void Pursuit() { //Check radius to see if player got out of range float distance = Vector2.Distance(transform.position, playerTransform.position); if (distance > pursuitRange) { //Player has escaped enemy enemyState = EnemyBaseState.Searching; pursuitState = PursuitState.Chasing; //reset timer = searchTime; } //Handle pursuit substates //Check if we are within attacking distance and not too close to player if (distance <= stoppingDistance && distance >= retreatDistance) { //Stop moving for a better attack shot //pursuitState = PursuitState.Stopped; rb.velocity = Vector2.zero; //stop enemy movement enemyState = EnemyBaseState.ChargingAttack; timer = 0f; //reset attackTimer = attackChargeTime; //Face the target as well } else if (distance < retreatDistance) { //If too close to player, retreat pursuitState = PursuitState.Retreating; } else { //Keep chasing pursuitState = PursuitState.Chasing; } }
void Pursuit() { //Check radius to see if player out of range float distance = Vector2.Distance(transform.position, player.transform.position); if (distance > pursuitRange) { //Player has escaped enemy spiderState = SpiderState.Searching; pState = PursuitState.Chasing; //reset projectileTimer = 0f; searchTimer = searchTime; return; } //Shoot projectile ShootProjectile(); //Check if we are within attacking distance and not too close to player if (distance <= stoppingDistance && distance >= retreatDistance) { //Stop moving for a better attack shot pState = PursuitState.Stopped; //Face the target as well } else if (distance < retreatDistance) { //If too close to player, retreat pState = PursuitState.Retreating; } else { //Keep chasing pState = PursuitState.Chasing; } }
//Reference to animator // Use this for initialization protected virtual void Start() { //Get player's script and controller //Get animator component //anim = GetComponent<Animator>(); Debug.Log("Base Start"); //Initialize to default values attackInfo = GetComponent <AttackInfoContainer> (); attackInfo.attackType = AttackType.MeleeWeakAttack; attackInfo.direction = Vector2.zero; attackInfo.force = baseAttackForce; //playerObject = GameObject.Find ("Player"); playerController = GameObject.Find("Player").GetComponent <PlayerController>(); playerTransform = GameObject.Find("Player").GetComponent <Transform> (); rb = GetComponent <Rigidbody2D> (); enemyState = EnemyBaseState.Roaming; pursuitState = PursuitState.Chasing; attackState = AttackState.Attacking; timer = 0f; attackTimer = 0f; flinchTimer = 0f; }