private void CreateStateMachine() { vehicleFSM = new StateMachineEngine(false); // Perceptions Perception radarBroken = vehicleFSM.CreatePerception <IsInStatePerception>(radar.GetComponent <RadarFSM>().GetRadarFSM(), "Broken"); Perception radarWorking = vehicleFSM.CreatePerception <IsInStatePerception>(radar.GetComponent <RadarFSM>().GetRadarFSM(), "Working"); Perception direct = vehicleFSM.CreatePerception <PushPerception>(); // States State runningState = vehicleFSM.CreateEntryState("Running", OnRunning); State speedUpState = vehicleFSM.CreateState("Speed up", SpeedUp); State slowDownState = vehicleFSM.CreateState("Slow down", SlowDown); // Transitions vehicleFSM.CreateTransition("Radar is broken", runningState, radarBroken, speedUpState); vehicleFSM.CreateTransition("Radar is working", speedUpState, radarWorking, slowDownState); vehicleFSM.CreateTransition("To running", slowDownState, direct, runningState); }
private void CreateFiniteStateMachine() { stateMachine = new StateMachineEngine(false); arriveToHouse = stateMachine.CreatePerception <ArriveToDestination>(new ArriveToDestination()); arriveToHouse.SetDestination(housePoint.position); ValuePerception enemyNear = stateMachine.CreatePerception <ValuePerception>(() => Vector3.Distance(transform.position, badBoy.transform.position) < 8); BehaviourTreeStatusPerception enterTheHouse = stateMachine.CreatePerception <BehaviourTreeStatusPerception>(behaviourTree, ReturnValues.Succeed); pointToRun = stateMachine.CreatePerception <ArriveToDestination>(new ArriveToDestination()); State goToHouse = stateMachine.CreateEntryState("Go to house", ToHouse); State subBehaviourTree = stateMachine.CreateSubStateMachine("Sub behaviour tree", behaviourTree); State runAway = stateMachine.CreateState("Run away", RunAway); State enterHouse = stateMachine.CreateState("Enter in house", EnterHouse); stateMachine.CreateTransition("To enter the house", goToHouse, arriveToHouse, subBehaviourTree); stateMachine.CreateTransition("To run away", goToHouse, enemyNear, runAway); behaviourTree.CreateExitTransition("Run away", subBehaviourTree, enemyNear, runAway); behaviourTree.CreateExitTransition("Enter the house", subBehaviourTree, enterTheHouse, enterHouse); stateMachine.CreateTransition("Stop running", runAway, pointToRun, goToHouse); }
private void CreateStateMachine() { // Perceptions massPutted = stateMachine.CreatePerception <TimerPerception>(1); tomatoPutted = stateMachine.CreatePerception <TimerPerception>(1); nextTopping = stateMachine.CreatePerception <TimerPerception>(1); allToppings = stateMachine.CreatePerception <PushPerception>(); // States State putMass = stateMachine.CreateEntryState("Put mass", PutMass); State putTomato = stateMachine.CreateState("Put tomato", PutTomato); State putTopping = stateMachine.CreateState("Put topping", PutTopping); // Transitions stateMachine.CreateTransition("Mass putted", putMass, massPutted, putTomato); stateMachine.CreateTransition("Tomato putted", putTomato, tomatoPutted, putTopping); stateMachine.CreateTransition("Next topping", putTopping, nextTopping, putTopping); // Super-node of the Behaviour Tree and exit transition subFSM = behaviourTree.CreateSubBehaviour("Sub-FSM", stateMachine, putMass); stateMachine.CreateExitTransition("Back to BT", putTopping, allToppings, ReturnValues.Succeed); }
private void CreateStateMachine() { // Perceptions WatchingPerception seePlayer = chickenFSM.CreatePerception <WatchingPerception>(new WatchingPerception(gameObject, target, visionCollider)); arriveToDestination = chickenFSM.CreatePerception <ArriveToDestination>(new ArriveToDestination()); Perception moveTimeout = chickenFSM.CreatePerception <TimerPerception>(5); Perception getDestinationOrTimeout = chickenFSM.CreateOrPerception <OrPerception>(moveTimeout, arriveToDestination); Perception timer = chickenFSM.CreatePerception <TimerPerception>(15); // States State idleState = chickenFSM.CreateEntryState("Idle", Idle); State chaseState = chickenFSM.CreateState("Chase", Chase); State moveState = chickenFSM.CreateState("Move around", MoveAround); // Transitios chickenFSM.CreateTransition("see the player from idle", idleState, seePlayer, chaseState); chickenFSM.CreateTransition("move randomly", idleState, timer, moveState); chickenFSM.CreateTransition("get to destination from chase", chaseState, arriveToDestination, idleState); //chickenFSM.CreateTransition("keep chasing", chaseState, seePlayer, chaseState); chickenFSM.CreateTransition("get to destination from move around", moveState, getDestinationOrTimeout, idleState); chickenFSM.CreateTransition("see the player from move around", moveState, seePlayer, chaseState); }
private void CreateSubMachine() { workingSubFSM = new StateMachineEngine(true); // Perceptions detectCar = workingSubFSM.CreatePerception <DetectCar>(new DetectCar(gameObject, pointToLook)); Perception carOverSpeed = workingSubFSM.CreatePerception <ValuePerception>(() => detectCar.GetCarSpeed() > 20); Perception carOnSpeed = workingSubFSM.CreatePerception <ValuePerception>(() => detectCar.GetCarSpeed() <= 20); Perception overSpeedLimit = workingSubFSM.CreateAndPerception <AndPerception>(detectCar, carOverSpeed); Perception onSpeedLimit = workingSubFSM.CreateAndPerception <AndPerception>(detectCar, carOnSpeed); Perception timeout = workingSubFSM.CreatePerception <TimerPerception>(2); // States State waitingForCarState = workingSubFSM.CreateEntryState("Waiting for car", OnWaitingForCar); State speedingState = workingSubFSM.CreateState("Speeding", OnSpeeding); State correctSpeedState = workingSubFSM.CreateState("Correct speed", OnCorrectSpeed); // Transitions workingSubFSM.CreateTransition("Car over speed limit", waitingForCarState, overSpeedLimit, speedingState); workingSubFSM.CreateTransition("Car on speed limit", waitingForCarState, onSpeedLimit, correctSpeedState); workingSubFSM.CreateTransition("To waiting for next bad car", speedingState, timeout, waitingForCarState); workingSubFSM.CreateTransition("To waiting for next good car", correctSpeedState, timeout, waitingForCarState); }
private void CreateStateMachine() { // Perceptions Perception click = testBoyFSM.CreatePerception <PushPerception>(); Perception clickOnMoving = testBoyFSM.CreatePerception <PushPerception>(); arriveToDestination = testBoyFSM.CreatePerception <ArriveToDestination>(new ArriveToDestination()); Perception timeToStopRunning = testBoyFSM.CreatePerception <TimerPerception>(7); Perception stopRunningAway = testBoyFSM.CreateOrPerception <OrPerception>(arriveToDestination, timeToStopRunning); Perception chickenNear = testBoyFSM.CreatePerception <ValuePerception>(() => distanceToChicken < minDistanceToChicken); // States State idleState = testBoyFSM.CreateEntryState("Idle"); State movingState = testBoyFSM.CreateState("Moving", Move); State runAwayState = testBoyFSM.CreateState("Run away", RunAway); // Transitions testBoyFSM.CreateTransition("mouse clicked", idleState, click, movingState); testBoyFSM.CreateTransition("get to destination from moving", movingState, stopRunningAway, idleState); testBoyFSM.CreateTransition("chicken near from idle", idleState, chickenNear, runAwayState); testBoyFSM.CreateTransition("get to destination from run away", runAwayState, stopRunningAway, idleState); testBoyFSM.CreateTransition("chicken near from moving", movingState, chickenNear, runAwayState); testBoyFSM.CreateTransition("change destination", movingState, clickOnMoving, movingState); }
private void CreateStateMachine() { radarFSM = new StateMachineEngine(false); // Perceptions Perception direct = radarFSM.CreatePerception <PushPerception>(); Perception breakDown = radarFSM.CreatePerception <TimerPerception>(30); Perception fix = radarFSM.CreatePerception <TimerPerception>(15); // States State entryState = radarFSM.CreateEntryState("Entry State"); State workingState = radarFSM.CreateSubStateMachine("Working", workingSubFSM); brokenState = radarFSM.CreateState("Broken", Broken); // Transitions radarFSM.CreateTransition("Direct", entryState, direct, workingState); workingSubFSM.CreateExitTransition("To broken", workingState, breakDown, brokenState); radarFSM.CreateTransition("To working", brokenState, fix, workingState); radarFSM.Fire("Direct"); }