private RoamingState() { if (_instance != null) { return; } _instance = this; }
void Start() { m_InputHandler = GetComponent <InputHandler>(); m_CreatureController = GetComponent <CreatureController>(); m_Nest = transform.parent.gameObject; m_NestXPos = m_Nest.transform.position.x; m_SpiritState = new SpiritState(this); m_IdleState = new IdleState(this); m_RoamingState = new RoamingState(this); m_CurrentState = m_IdleState; if (m_CurrentState != null && !m_InputHandler.PlayerControlled) { m_CurrentState.Enter(); } }
private void MakeFSM() { Vector3 target = new Vector3(Random.Range(transform.position.x - 5.0f, transform.position.x + 5.0f), Random.Range(transform.position.y - 5.0f, transform.position.y + 5.0f)); RoamingState follow = new RoamingState(target); follow.AddTransition(Transition.SawPlayer, StateID.ChasePlayer); FollowPlayerState chase = new FollowPlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowPath); chase.AddTransition(Transition.NearPlayer, StateID.AttackPlayer); ShootPlayerState attack = new ShootPlayerState(); attack.AddTransition(Transition.SawPlayer, StateID.ChasePlayer); sm = new FSMSystem(); sm.AddState(follow); sm.AddState(chase); sm.AddState(attack); }
public IBehaviorState StateFactory(States state) { IBehaviorState ret = null; switch (state) { case States.Idling: break; case States.Roaming: ret = new RoamingState(host) as IBehaviorState; break; case States.Pursuing: ret = new PursuingState(host) as IBehaviorState; break; case States.Fighting: ret = new FightingState(host) as IBehaviorState; break; case States.Ranged: ret = new RangedCombatState(host) as IBehaviorState; break; case States.Melee: ret = new MeleeCombatState(host) as IBehaviorState; break; } if (ret != null) { ret.Init(this); } return(ret); }
void Roaming() { switch (_currentRoamingState) { case RoamingState.NONE: break; case RoamingState.LOOKING_FOR_TARGET: targetLocation = RandomPointInPlayerSphere(); _currentRoamingState = RoamingState.MOVING; break; case RoamingState.MOVING: transform.position = Vector3.MoveTowards(transform.position, targetLocation,Time.deltaTime / movementRate); if (ReachedTarget()) _currentRoamingState = RoamingState.REACHED_TARGET; break; case RoamingState.REACHED_TARGET: _currentAIState = AIStates.DECIDING; break; default: throw new ArgumentOutOfRangeException(); } }
void ResetAIStates() { idleTimeLeft = Random.Range(5, 10); _currentReturningState = ReturningState.NONE; _currentIdleState = IdleState.NONE; _currentRoamingState = RoamingState.NONE; _currentPlayingState = PlayingState.NONE; }
void Deciding() { ResetAIStates(); if (IsOutOfPlayerLimits()) { _currentAIState = AIStates.RETURNING; if (_currentReturningState == ReturningState.NONE) _currentReturningState = ReturningState.LOOKING_FOR_TARGET; } else { if (Random.value < 0.5f) { _currentAIState = AIStates.IDLING; if (_currentIdleState == IdleState.NONE) _currentIdleState = IdleState.DOIN_MY_THANG; } else { _currentAIState = AIStates.ROAMING; if (_currentRoamingState == RoamingState.NONE) _currentRoamingState = RoamingState.LOOKING_FOR_TARGET; } } }
public bool IsInState(RoamingState stateInQuestion) { return (State & stateInQuestion) == stateInQuestion; }