public void MakeFSM() { IdleState idle = new IdleState(); idle.AddTransition(Transition.SawPlayer, StateID.AttackingState); idle.AddTransition(Transition.LostPlayer, StateID.MovingState); MoveState move = new MoveState(); move.AddTransition(Transition.SawPlayer, StateID.AttackingState); AttackState attack = new AttackState(); attack.AddTransition(Transition.LostPlayer, StateID.MovingState); attack.AddTransition(Transition.IdleTransition, StateID.IdleStateID); DefendState defend = new DefendState(); EvadeState evade = new EvadeState(); WinState win = new WinState(); DeathState death = new DeathState(); fsm = new FSMSystem(); fsm.AddState(move); fsm.AddState(attack); fsm.AddState(idle); fsm.AddState(defend); fsm.AddState(evade); fsm.AddState(win); fsm.AddState(death); }
// Use this for initialization void Awake() { attackState = new AttackState(this); chaseState = new ChaseState(this); evadeState = new EvadeState(this); orbitState = new OrbitState(this); }
private void Awake() { my = this; target = GameObject.FindGameObjectWithTag("Character").GetComponent <Entity>(); restpoint = GameObject.Find("AIrestpoint"); attackState = new AttackState(this); evadeState = new EvadeState(this); followState = new FollowState(this); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } bool enemyClose = false; bool obstacleClose = false; IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); foreach (DataCreature data in creatures) { Agent agent = data.creature?.agentCreature; if (!agent || !agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 5f) { continue; } bool isHostil = CreatureIsHostil(owner, agent.Creature); if (isHostil && Vector3.Distance(owner.transform.position, agent.transform.position) < owner.PerceptionConfig.viewRadius / 4) { enemyClose = true; break; } } DataObstacle obstacle = owner.Memory.Obstacles.Read().FirstOrDefault(data => MaxColliderSize(data.collider) >= 2f); obstacleClose = obstacle != null; switch (evadeState) { case EvadeState.Flee: if (!enemyClose && obstacleClose) { child.Abort(); AddSubgoal(new GoalHide(owner)); evadeState = EvadeState.Hide; } break; case EvadeState.Hide: if (enemyClose) { child.Abort(); AddSubgoal(new GoalFlee(owner)); evadeState = EvadeState.Flee; } break; } base.ProcessSubgoals(); }
private void ConstructFSM() { //Get the list of points pointList = GameObject.FindGameObjectsWithTag("WandarPoint"); Transform[] waypoints = new Transform[pointList.Length]; int i = 0; foreach (GameObject obj in pointList) { waypoints[i] = obj.transform; i++; } PatrolState patrol = new PatrolState(waypoints); patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead); patrol.AddTransition(Transition.Panic, FSMStateID.Fleeing); ChaseState chase = new ChaseState(waypoints); chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking); chase.AddTransition(Transition.NoHealth, FSMStateID.Dead); chase.AddTransition(Transition.Panic, FSMStateID.Fleeing); AttackState attack = new AttackState(waypoints); attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing); attack.AddTransition(Transition.NoHealth, FSMStateID.Dead); attack.AddTransition(Transition.Panic, FSMStateID.Fleeing); attack.AddTransition(Transition.TooCloseTooPlayer, FSMStateID.Evade); DeadState dead = new DeadState(); dead.AddTransition(Transition.NoHealth, FSMStateID.Dead); FleeState flee = new FleeState(); flee.AddTransition(Transition.NoHealth, FSMStateID.Dead); flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling); EvadeState evade = new EvadeState(); evade.AddTransition(Transition.NoHealth, FSMStateID.Dead); evade.AddTransition(Transition.OutOfEvadingRange, FSMStateID.Patrolling); AddFSMState(patrol); AddFSMState(chase); AddFSMState(attack); AddFSMState(dead); AddFSMState(flee); AddFSMState(evade); }
/// <summary> /// Evaluates the update. /// </summary> /// <param name="gameTime">The game time.</param> internal void EvaluateUpdate(TimeSpan gameTime) { if (this.Strategy.NeedToEvade(gameTime)) { this.Strategy.Evade(gameTime); this.State = EvadeState.Evading; } else { this.MoveBehavior.Move(gameTime); this.State = EvadeState.Moving; } }
public BasicMachine(Character character) : base(character) { // States StarState star = new StarState(character); EvadeState evade = new EvadeState(character); DeadState die = new DeadState(character); ChaseLifeState chase = new ChaseLifeState(character); // Add states this.states.Add(star); this.states.Add(evade); this.states.Add(die); this.states.Add(chase); this.initialState = this.currentState = star; }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } bool playerClose = owner.Memory.Player.lastSeeTime > Time.time - 5f && Vector3.Distance(owner.transform.position, Player.Instance.transform.position) < owner.PerceptionConfig.viewRadius / 4; DataObstacle obstacle = owner.Memory.Obstacles.Read().FirstOrDefault(data => MaxColliderSize(data.collider) >= 2f); bool obstacleClose = obstacle != null; switch (evadeState) { case EvadeState.Flee: if (!playerClose && obstacleClose) { child.Abort(); AddSubgoal(new GoalHidePlayer(owner)); evadeState = EvadeState.Hide; } break; case EvadeState.Hide: if (playerClose) { child.Abort(); AddSubgoal(new GoalFleePlayer(owner)); evadeState = EvadeState.Flee; } break; } base.ProcessSubgoals(); }
//=================================================================================================================o void EvadeReset() { if (doSwitchDel != null) { doSwitchDel (false); } // Double tab is false in HeroMotor // Switch to Normal or Combat if last states are.. if ((MainState)lastMainState == MainState.Balance || (MainState)lastMainState == MainState.Falling || (MainState)lastMainState == MainState.Jumping) { bool inCombat = sword_Hand.active || bow_Hand.active || rifle_Hand.active || pistol_Hand.active; mainState = inCombat ? MainState.Combat : MainState.Normal; } else mainState = (MainState)lastMainState; // Last state before evading // Reset procedural motion rotations currRot = Mathf.Lerp(currRot, 0f, Time.deltaTime); leanRot = 0f; evadeState = EvadeState.None; // Out }
//=================================================================================================================o void DoEvade(string s) { if (s == "W") evadeState = EvadeState.Forward; else if (s == "S") evadeState = EvadeState.Backward; else if (s == "A") evadeState = EvadeState.Left; else if (s == "D") evadeState = EvadeState.Right; if (evadeState != EvadeState.None) { lastMainState = (int)mainState; mainState = MainState.Evade; } }
//=================================================================================================================o void Start() { hero = transform; //a = GetComponent <Animation>() as Animation; if (a.clip) { aC = a.clip; } else aC = a["idle"].clip; impactM = a["land"].clip; hMotor = GetComponent <HeroMotor>() as HeroMotor; hClimb = GetComponent <HeroClimb>() as HeroClimb; hPhys = GetComponent <HeroPhysic>() as HeroPhysic; hSwim = GetComponent <HeroSwim>() as HeroSwim; hKey = GetComponent <HeroKeymap>() as HeroKeymap; // Pass Delegates hMotor.doJumpDel += DoJump; hMotor.doBalanceDel += DoBalance; hMotor.doCombatDel += DoCombat; hMotor.doSwitchWeapDel += DoSwitchWeapons; hMotor.doEvadeDel += DoEvade; hMotor.doSneakDel += DoSneak; hClimb.doClimbDel += DoClimb; hSwim.doSwimDel += DoSwim; hPhys.doPhysDel += DoPhysx; currRot = 0.0f; leanRot = 0.0f; //sprintRot = 0.0f; lastRootForward = hero.forward; // Start is in Weaponstate.None, weaponless // Sword if (sword_Hand == null) // If no weapon is assigned { sword_Hand = new GameObject("emptyObj"); sword_Hand.active = false; } else sword_Hand.active = false; if (sword_Holster == null) // If no weapon is assigned { sword_Holster = new GameObject("emptyObj"); sword_Holster.active = false; } else sword_Holster.active = false; // Bow if (bow_Hand == null) // If no weapon is assigned { bow_Hand = new GameObject("emptyObj"); bow_Hand.active = false; } else bow_Hand.active = false; if (bow_Holster == null) // If no weapon is assigned { bow_Holster = new GameObject("emptyObj"); bow_Holster.active = false; } else bow_Holster.active = false; // Quiver if (bow_Quiver == null) // If no weapon is assigned { bow_Quiver = new GameObject("emptyObj"); bow_Quiver.active = false; } else bow_Quiver.active = false; // Rifle if (rifle_Hand == null) // If no weapon is assigned { rifle_Hand = new GameObject("emptyObj"); rifle_Hand.active = false; } else rifle_Hand.active = false; if (rifle_Holster == null)// If no weapon is assigned { rifle_Holster = new GameObject("emptyObj"); rifle_Holster.active = false; } else rifle_Holster.active = false; // Pistol if (pistol_Hand == null)// If no weapon is assigned { pistol_Hand = new GameObject("emptyObj"); pistol_Hand.active = false; } else pistol_Hand.active = false; if (pistol_Holster == null)// If no weapon is assigned { pistol_Holster = new GameObject("emptyObj"); pistol_Holster.active = false; } else pistol_Holster.active = false; // Look for setup DoSwitchWeapons (); actionState = ActionState.None; evadeState = EvadeState.None; climbState = ClimbState.None; }
private void Awake() { evadeState = new EvadeState(this); approachState = new ApproachState(this); wanderState = new WanderState(this); }