// The NPC has two states: FollowPath and ChasePlayer // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath private void MakeFSM() { FollowPathState follow = new FollowPathState(/*path*/); follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer); ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath); PatrolState patrolState = new PatrolState(PatrolWayPoints); patrolState.AddTransition(Transition.Alert, StateID.AlertNpc); AlertState alertState = new AlertState(); alertState.AddTransition(Transition.Attack, StateID.AttackingPlayer); alertState.AddTransition(Transition.Patrol, StateID.Patroling); AttackState attackState = new AttackState(); attackState.AddTransition(Transition.Alert, StateID.AlertNpc); fsm = new FSMSystem(); fsm.AddState(patrolState); fsm.AddState(alertState); fsm.AddState(attackState); //fsm.AddState(chase); //fsm.AddState(follow); Debug.Log("First State: " + fsm.CurrentState.ToString()); }
// The NPC has two states: FollowPath and ChasePlayer // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath private void MakeFSM() { FollowPathState follow = new FollowPathState(path); follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer); ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath); fsm = new FSMSystem(); fsm.AddState(follow); fsm.AddState(chase); }
// Use this for initialization void Start() { // Self references this.dangerHitbox = this.transform.FindChild("Danger Zone").gameObject; this.targetingCone = this.transform.FindChild("Line of Sight").gameObject; _bodyBounds = CreateBodyBounds(); Fsm = new StateMachine <Enemy>(this); State <Enemy> state; switch (this.startState) { case StartState.Wander: state = new WanderState(this, Fsm, 30.0f); break; case StartState.ReachGoal: state = new ReachGoalState(this, Fsm, target); break; case StartState.Flock: state = new FlockState(this, Fsm, target, group); break; case StartState.Flee: state = new FleeState(this, Fsm, target); break; case StartState.FleeMultiple: state = new FleeMultipleState(this, Fsm, group); break; case StartState.FollowPath: Debug.Log("Setting state"); state = new FollowPathState(this, Fsm, PathFinding.spawnGameObjectsAtPathPoints(PathFinding.generatePath(gameObject, target))); Debug.Log("Done setting state"); break; case StartState.SeekTargetWithPath: state = new SeekTargetWithPathState(this, Fsm, target); break; case StartState.Patrol: state = new PatrolState(this, Fsm, patrolPath, patrolPauseTime); break; default: state = new WanderState(this, Fsm, 30.0f); break; } Fsm.InitialState(state); SetDangerous(false); }
void MakeFSM() { FollowPathState state1 = new FollowPathState (path); state1.AddTransition (Transition.SawPlayer, StateID.ChasingPlayer); ChasePlayerState state2 = new ChasePlayerState (); state2.AddTransition (Transition.LostPlayer, StateID.FollowingPath); fsm = new FSMSystem (); fsm.AddState (state1); fsm.AddState (state2); }
private void MakeFSM() { FollowPathState follow = new FollowPathState(playerCharacterParameters.retreatRadius); follow.AddTransition(Transition.SawEnemy, StateID.ChasingEnemy); ChasePlayerState chase = new ChasePlayerState(playerCharacterParameters.retreatRadius); chase.AddTransition(Transition.LostEnemy, StateID.FollowingPath); fsm = new FSMSystem(); fsm.AddState(follow); fsm.AddState(chase); }
//NPC有两个状态分别是在路径中巡逻和追逐玩家 //如果他在第一个状态并且SawPlayer 过度状态被出发了,它就转变到ChasePlayer状态 //如果他在ChasePlayer状态并且LostPlayer状态被触发了,它就转变到FollowPath状态 private void MakeFSM()//建造状态机 { FollowPathState follow = new FollowPathState(path); follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer); ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath); fsm = new FSMSystem(); fsm.AddState(follow);//添加状态到状态机,第一个添加的状态将作为初始状态 fsm.AddState(chase); }
void MakeFSM() { FollowPathState state1 = new FollowPathState(path); state1.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer); ChasePlayerState state2 = new ChasePlayerState(); state2.AddTransition(Transition.LostPlayer, StateID.FollowingPath); fsm = new FSMSystem(); fsm.AddState(state1); fsm.AddState(state2); }
private void MakeFSM() { //巡逻状态 FollowPathState follow = new FollowPathState(path); follow.AddTransition(zhuangtaiji.Transition.sawPlayer, zhuangtaiji.StateID.ChasingPlayer); //追逐状态 ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(zhuangtaiji.Transition.lostPlayer, zhuangtaiji.StateID.FollowingPath); //初始化状态机 fsm = new zhuangtaiji.FSMSystem(gameObject.transform, follow.wayPoints[follow.currentWayPoint]); fsm.AddState(follow); fsm.AddState(chase); }
private void MakeFSM() { FollowPathState follow = new FollowPathState(path); follow.AddTransition(Transition.SawPlayer, StateID.ChasePlayer); ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowPath); chase.AddTransition(Transition.NearPlayer, StateID.AttackPlayer); AttackPlayerState attack = new AttackPlayerState(); attack.AddTransition(Transition.SawPlayer, StateID.ChasePlayer); sm = new FSMSystem(); sm.AddState(follow); sm.AddState(chase); sm.AddState(attack); }
public void MakeFSM() { //List<Node> tempPath = GetComponent<FindPath>().GetFinalPath(this.gameObject, target); List <Node> tempPath = myAxing.GetFinalPath(this.gameObject, target); follow = new FollowPathState(); follow.SetWayPoints(tempPath); follow.AddTransition(Transition.SeePlayerTrans, StateID.ChaseingplayerId); chase = new ChasePlayerState(); chase.AddTransition(Transition.LosePlayerTrans, StateID.FollowPathId); fsm = new FSM_Manager(); fsm.AddFsmState(follow); fsm.AddFsmState(chase); //SetTransition(Transition.LosePlayerTrans); }
// Use this for initialization void Start() { _bodyBounds = CreateBodyBounds(); Fsm = new StateMachine <Enemy>(this); State <Enemy> state; switch (this.startState) { case StartState.Wander: state = new WanderState(this, Fsm, 30.0f); break; case StartState.ReachGoal: state = new ReachGoalState(this, Fsm, target); break; case StartState.Flock: state = new FlockState(this, Fsm, target, group); break; case StartState.Flee: state = new FleeState(this, Fsm, target); break; case StartState.FleeMultiple: state = new FleeMultipleState(this, Fsm, group); break; case StartState.FollowPath: Debug.Log("Setting state"); state = new FollowPathState(this, Fsm, PathFinding.spawnGameObjectsAtPathPoints(PathFinding.generatePath(gameObject, target))); Debug.Log("Done setting state"); break; case StartState.SeekTargetWithPath: state = new SeekTargetWithPathState(this, Fsm, target); break; default: state = new WanderState(this, Fsm, 30.0f); break; } Fsm.InitialState(state); }
//Finite State Machine Setup public void SetupFSM() { FollowPathState followState = new FollowPathState(); followState.SetAgentHandler(this); followState.AddTransitionToState(fsmTransition.ToChase, fsmStateID.ChasePlayer); followState.AddTransitionToState(fsmTransition.ToAttack, fsmStateID.AttackPlayer); AttackState attackState = new AttackState(); attackState.AddTransitionToState(fsmTransition.ToLostPlayer, fsmStateID.FollowPath); attackState.AddTransitionToState(fsmTransition.ToChase, fsmStateID.ChasePlayer); ChasePlayerState chaseState = new ChasePlayerState(); chaseState.AddTransitionToState(fsmTransition.ToLostPlayer, fsmStateID.FollowPath); chaseState.AddTransitionToState(fsmTransition.ToAttack, fsmStateID.AttackPlayer); mBasicAgentFSM = new FiniteStateMachine(); mBasicAgentFSM.AddState(attackState); mBasicAgentFSM.AddState(followState); mBasicAgentFSM.AddState(chaseState); }
// The NPC has two states: FollowPath and ChasePlayer // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath private void MakeFSM() { ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath); Vector3[] path = new Vector3[waypoint[0].childCount]; for (int i = 0; i < waypoint[0].childCount; i++) { path[i] = waypoint[0].GetChild(i).position; } FollowPathState follow = new FollowPathState(path); follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer); fsm = new FSMSystem(); fsm.AddState(follow); fsm.AddState(chase); }