// Update is called once per frame void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDER); break; case State.WANDER: if (SensingUtils.DistanceToTarget(gameObject, theHen) <= blackboard.chickDetectionRadius / 3) { ChangeState(State.FLEE); break; } break; case State.FLEE: if (SensingUtils.DistanceToTarget(gameObject, theHen) >= blackboard.chickFarEnoughRadius * 1.5) { ChangeState(State.WANDER); break; } break; } }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.NORMAL); break; case State.NORMAL: peril = SensingUtils.FindInstanceWithinRadius(gameObject, "BATCAT", blackboard.perilDetectableRadius); if (peril != null) { ChangeState(State.SCARED); break; } // do nothing in particular while in this state break; case State.SCARED: if (SensingUtils.DistanceToTarget(gameObject, peril) >= blackboard.perilSafetyRadius) { ChangeState(State.NORMAL); } // do nothing in particular, while in this state break; } }
// Update is called once per frame void Update() { if (SensingUtils.DistanceToTarget(this.gameObject, cemetery) < 10) { Object.Destroy(this.gameObject); } }
// Update is called once per frame void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.GO_TO_TARGET); break; case State.GO_TO_TARGET: if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadius) { ChangeState(State.GO_TO_EXIT); } break; case State.GO_TO_EXIT: if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadius) { Destroy(this); } break; } }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.CAMPING); break; case State.CAMPING: if (SensingUtils.DistanceToTarget(gameObject, GameController.Instance.playerController) <= blackboard.PlayerDetectionRadius && GameController.Instance.civilianGlobalBB.CivilianFollowingCounter < GameController.Instance.civilianGlobalBB.MaxCiviliansFollowing) { ChangeState(State.FOLLOWING); break; } break; case State.FOLLOWING: if (SensingUtils.DistanceToTarget(gameObject, GameController.Instance.playerController) > blackboard.farAwayPlayerRadius) { ChangeState(State.CAMPING); break; } break; } }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.POLLINATING); break; case State.POLLINATING: mosquito = SensingUtils.FindInstanceWithinRadius(gameObject, "BOID", blackboard.perilDetectableRadius); if (mosquito != null) { ChangeState(State.DEFEND); break; } break; case State.DEFEND: if (!mosquito || SensingUtils.DistanceToTarget(gameObject, mosquito) >= blackboard.perilSafetyRadius) { ChangeState(State.POLLINATING); } break; } // end of switch }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(1)) { var position = cam.ScreenToWorldPoint(Input.mousePosition); position.z = 0; GameObject worm = GameObject.Instantiate(wormPrefab); worm.transform.position = position; worm.transform.Rotate(0, 0, Random.value * 360); } if (Input.GetMouseButtonDown(0)) { var position = cam.ScreenToWorldPoint(Input.mousePosition); position.z = 0; dummy.transform.position = position; GameObject worm = SensingUtils.FindInstanceWithinRadius(dummy, "WORM", 10); if (worm != null) { Destroy(worm); } } if (Input.GetMouseButtonDown(2)) { var position = cam.ScreenToWorldPoint(Input.mousePosition); position.z = 0; GameObject worm = GameObject.Instantiate(chickPrefab); worm.transform.position = position; worm.transform.Rotate(0, 0, Random.value * 360); } }
// Update is called once per frame void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.NORAMAL); break; case State.NORAMAL: float Distance = SensingUtils.DistanceToTarget(gameObject, MouseBB.Roomba); if (Distance < MouseBB.roombaDetectionRadius) { OBTarget = MouseBB.NearestExitPoint(); if (AngleBetween(gameObject, MouseBB.Roomba, OBTarget) > 30) { ChangeState(State.FLEE); } } break; case State.FLEE: if (RouterExecutor.currentState == FSM_RouteExecutor.State.TERMINATED) { ChangeState(State.DESTROY); } break; case State.DESTROY: Destroy(gameObject); break; } }
bool FindZombie(GameObject currentZombie, GameObject newZombie) { if (newZombie != null && newZombie != currentZombie && SensingUtils.DistanceToTarget(gameObject, newZombie) < SensingUtils.DistanceToTarget(gameObject, currentZombie)) { SetFleeTarget(newZombie); return(true); } return(false); }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDERING); break; case State.REACHING_FLOWER: if (SensingUtils.DistanceToTarget(gameObject, flower) < blackboard.placeReachedRadius) // trashcan reached? { ChangeState(State.POLLINATING); break; } // do nothing while in this state break; case State.REACHING_RUSC: if (SensingUtils.DistanceToTarget(gameObject, blackboard.rusc) < blackboard.placeReachedRadius) //hideout reached? { ChangeState(State.WANDERING); Destroy(honey); break; } // do nothing while in this state break; case State.POLLINATING: if (elapsedTime >= blackboard.rummageTime) // food found? { ChangeState(State.REACHING_RUSC); Bite(flower); break; } elapsedTime += Time.deltaTime; // remember, cheese is highly volatile. it may "disappear" if (flower == null || flower.Equals(null)) { // if it has vanished just forget about it wander and wander again ChangeState(State.WANDERING); break; } break; case State.WANDERING: flower = SensingUtils.FindInstanceWithinRadius(gameObject, "Flower", blackboard.flowerDetectableRadius); if (flower != null) // trash can detected? { ChangeState(State.REACHING_FLOWER); break; } // do nothing while in this state. break; } // end of switch }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDERING); break; case State.EATING: if (elapsedTime >= blackboard.eatingTime) // time to finish eating? { ChangeState(State.WANDERING); break; } elapsedTime += Time.deltaTime; break; case State.REACHING_CAN: if (SensingUtils.DistanceToTarget(gameObject, trashCan) < blackboard.placeReachedRadius) // trashcan reached? { ChangeState(State.RUMMAGING); break; } // do nothing while in this state break; case State.REACHING_HIDEOUT: if (SensingUtils.DistanceToTarget(gameObject, blackboard.hideout) < blackboard.placeReachedRadius) //hideout reached? { ChangeState(State.EATING); break; } // do nothing while in this state break; case State.RUMMAGING: if (elapsedTime >= blackboard.rummageTime) // food found? { ChangeState(State.REACHING_HIDEOUT); break; } elapsedTime += Time.deltaTime; break; case State.WANDERING: trashCan = SensingUtils.FindInstanceWithinRadius(gameObject, "TRASH_CAN", blackboard.trashcanDetectableRadius); if (trashCan != null) // trash can detected? { ChangeState(State.REACHING_CAN); break; } // do nothing while in this state. break; } // end of switch }
bool CheckIfDustInLargeRange() { GameObject dust; dust = SensingUtils.FindRandomInstanceWithinRadius(gameObject, "DUST", myBlackBoard.farDustDetectionRadius); if (dust != null) { return(true); } return(false); }
bool CheckIfPooInCloseRange() { GameObject poo; poo = SensingUtils.FindInstanceWithinRadius(gameObject, "POO", myBlackBoard.closeDustDetectionRadius); if (poo != null) { return(true); } return(false); }
bool CheckIfPooInLargeRange() { GameObject poo; poo = SensingUtils.FindRandomInstanceWithinRadius(gameObject, "POO", myBlackBoard.farPooDetectionRadius); if (poo != null) { return(true); } return(false); }
// BB engine OnUpdate method public override TaskStatus OnUpdate() { if (SensingUtils.DistanceToTarget(gameObject, target) <= closeEnough) { arrive.enabled = false; return(TaskStatus.COMPLETED); // COMPLETED = SUCCESSFUL termination } else { return(TaskStatus.RUNNING); // RUNNING = not COMPLETED yet } }
public override TaskStatus OnUpdate() { instance = SensingUtils.FindInstanceWithinRadius(gameObject, tag, radius); if (instance == null) { return(TaskStatus.FAILED); } else { return(TaskStatus.COMPLETED); } }
// ////SENSE EXTRA FUNCTIONS//// // bool CheckIfDustInCloseRange() { GameObject dust; dust = SensingUtils.FindInstanceWithinRadius(gameObject, "DUST", myBlackBoard.closeDustDetectionRadius); if (dust != null && !dust.Equals(targetedDust)) { targetedDust = dust; return(true); } return(false); }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDERING); break; case State.WANDERING: zombie = SensingUtils.FindInstanceWithinRadius(gameObject, blackboard.zombieTag, blackboard.nearbyZombieRadius); if (zombie != null) { ChangeState(State.FLEEING); } break; case State.FLEEING: if (zombie != null) { otherZombie = SensingUtils.FindInstanceWithinRadius(gameObject, blackboard.zombieTag, blackboard.nearbyZombieRadius); if (FindZombie(zombie, otherZombie)) { zombie = null; break; } } else { zombie = SensingUtils.FindInstanceWithinRadius(gameObject, blackboard.zombieTag, blackboard.nearbyZombieRadius); if (FindZombie(otherZombie, zombie)) { otherZombie = null; break; } } if (SensingUtils.DistanceToTarget(gameObject, flee.target) >= blackboard.farAwayZombieRadius) { ChangeState(State.WANDERING); break; } break; } }
public GameObject NearestExitPoint() { GameObject nearest = exitPoints[0]; float best = SensingUtils.DistanceToTarget(gameObject, nearest); float current; // process all exit points. Retain the nearest for (int i = 1; i < exitPoints.Length; i++) { current = SensingUtils.DistanceToTarget(gameObject, exitPoints[i]); if (current < best) { best = current; nearest = exitPoints[i]; } } return(nearest); }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.FOLLOWING_MARINE); break; case State.FOLLOWING_MARINE: if (SensingUtils.DistanceToTarget(gameObject, blackboard.militarBase) < blackboard.MilitarBaseDetectableRadius) { bird = SensingUtils.FindInstanceWithinRadius(gameObject, "Bird", blackboard.birdDetectionRadius); if (bird != null) { if (SensingUtils.DistanceToTarget(gameObject, bird) > blackboard.birdScareRadius) { ChangeState(State.GOING_BASE); break; } break; } else { ChangeState(State.GOING_BASE); break; } } break; case State.GOING_BASE: if (SensingUtils.DistanceToTarget(gameObject, blackboard.militarBase) < blackboard.nearbyMilitarBaseRadius) { ChangeState(State.CIVILIAN_SAVED); break; } break; case State.CIVILIAN_SAVED: break; } }
public override bool Check() { float distance = SensingUtils.DistanceToTarget(gameObject, attractor); // out of safety area? return true // inside of extra safety area? return false // otherwise return what was returned the previus tick if (distance > safetyRadius) { lastTick = true; return(lastTick); } if (distance <= extraSafetyRadius) { lastTick = false; return(lastTick); } return(lastTick); }
// Update is called once per frame void Update() { switch (currentState) { case State.Initial: ChangeState(State.Wandering); break; case State.Wandering: target = SensingUtils.FindInstanceWithinRadius(this.gameObject, "Player", blackboard.RadiusDetection); if (target != null) { ChangeState(State.Follow); } break; case State.Follow: if (SensingUtils.DistanceToTarget(this.gameObject, target) <= blackboard.HitDistance) { ChangeState(State.Hit_Target); } if (SensingUtils.DistanceToTarget(this.gameObject, target) > blackboard.EscapeDistance) { ChangeState(State.Wandering); } break; case State.Hit_Target: if (SensingUtils.DistanceToTarget(this.gameObject, target) > blackboard.HitDistance) { ChangeState(State.Follow); } break; } }
public static SteeringOutput GetSteering(KinematicState ownKS, GameObject attractor, float seekWeight, string idTag, float cohesionThreshold, float repulsionThreshold, float wanderRate, float vmWeight, float rpWeight, float coWeight, float wdWeight, float distance, float angle, ref bool previous, GameObject self, float tooClose, float safe) { if (previous) { if (SensingUtils.DistanceToTarget(self, attractor) >= safe) { previous = false; //Vector3 pepe = Utils.OrientationToVector(attractor.GetComponent<KinematicState>().orientation + angle).normalized * distance; //SURROGATE_TARGET.transform.position = attractor.transform.position + pepe; return(FlockingAround.GetSteering(ownKS, attractor, seekWeight, idTag, cohesionThreshold, repulsionThreshold, wanderRate, vmWeight, rpWeight, coWeight, wdWeight)); } else { return(Flee.GetSteering(ownKS, attractor)); } } else { if (SensingUtils.DistanceToTarget(self, attractor) < tooClose) { previous = true; return(Flee.GetSteering(ownKS, attractor)); } else { //Vector3 pepe = Utils.OrientationToVector(attractor.GetComponent<KinematicState>().orientation + angle).normalized * distance; //SURROGATE_TARGET.transform.position = attractor.transform.position + pepe; return(FlockingAround.GetSteering(ownKS, attractor, seekWeight, idTag, cohesionThreshold, repulsionThreshold, wanderRate, vmWeight, rpWeight, coWeight, wdWeight)); } } }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.PATROLLING); break; case State.PATROLLING: flare = SensingUtils.FindInstanceWithinRadius(gameObject, "Flare", blackboard.flareDetectableRadius); if (flare != null) { ChangeState(State.ALARM); break; } if (GameController.Instance.zombieGlobalBB.flare != null) { flare = GameController.Instance.zombieGlobalBB.flare; ChangeState(State.GOING_TO_FLARE); break; } break; case State.ALARM: GameController.Instance.zombieGlobalBB.AnnounceFlare(flare); ChangeState(State.GOING_TO_FLARE); break; case State.GOING_TO_FLARE: if (flare == null || flare.Equals(null)) { ChangeState(State.PATROLLING); } break; } }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDERING); break; case State.WANDERING: civilian = SensingUtils.FindInstanceWithinRadius(gameObject, blackboard.civilianTag, blackboard.civilianDetectableRadius); if (civilian != null) { ChangeState(State.PURSUING); break; } break; case State.PURSUING: if (civilian == null || civilian.Equals(null)) { ChangeState(State.WANDERING); break; } if (SensingUtils.DistanceToTarget(gameObject, civilian) < blackboard.nearbyCivilianRadius) { ChangeState(State.KILL_CIVILIAN); break; } break; case State.KILL_CIVILIAN: ChangeState(State.WANDERING); break; } }
void Update() { // do this no matter the state UpdateHunger(); switch (currentState) { case State.INITIAL: ChangeState(State.RETURNING); break; case State.HIDING: mouse = SensingUtils.FindInstanceWithinRadius(gameObject, "MOUSE", blackboard.mouseDetectableRadius); if (mouse != null) // mouse detected ? { ChangeState(State.PURSUING); break; } // do nothing while in this state break; case State.PURSUING: if (SensingUtils.DistanceToTarget(gameObject, mouse) <= blackboard.mouseReachedRadius) // mouse reached? // stop the mouse: disable all its steering behaviours /* SteeringBehaviour[] sts = mouse.GetComponents<SteeringBehaviour> (); * foreach (SteeringBehaviour st in sts) * st.enabled = false; */ // "take the mouse" { mouse.transform.parent = gameObject.transform; mouse.tag = "TRAPPED_MOUSE"; // start transporting the mouse ChangeState(State.TRANSPORTING); break; } GameObject otherMouse = SensingUtils.FindInstanceWithinRadius(gameObject, "MOUSE", blackboard.mouseDetectableRadius); if (otherMouse != null && otherMouse != mouse && SensingUtils.DistanceToTarget(gameObject, otherMouse) < SensingUtils.DistanceToTarget(gameObject, mouse)) { // if there's another mouse that is closer to me than the one I'm pursuing, "retarget" mouse = otherMouse; break; } if (SensingUtils.DistanceToTarget(gameObject, mouse) >= blackboard.mouseHasVanishedRadius) // mouse vanished? { ChangeState(State.RETURNING); break; } if (pursuingTime >= blackboard.maxPursuingTime) // pursuing this target takes too long? { ChangeState(State.RESTING); break; } // increase pursuing time pursuingTime += Time.deltaTime; break; case State.TRANSPORTING: if (SensingUtils.DistanceToTarget(gameObject, blackboard.jail) < blackboard.placeReachedRadius) // mice-jail reached? // "drop" the mouse { mouse.transform.parent = null; ChangeState(State.RETURNING); break; } // do nothing while in this state break; case State.RETURNING: mouse = SensingUtils.FindInstanceWithinRadius(gameObject, "MOUSE", blackboard.mouseDetectableRadius); if (mouse != null) // mouse detected ? { ChangeState(State.PURSUING); break; } if (SensingUtils.DistanceToTarget(gameObject, blackboard.hideout) < blackboard.placeReachedRadius) // hideout reached? { ChangeState(State.HIDING); break; } // do nothing while in this state break; case State.RESTING: if (restingTime >= blackboard.maxRestingTime) // fresh again? { ChangeState(State.RETURNING); break; } restingTime += Time.deltaTime; break; } // end of switch }
// Update is called once per frame void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDER); break; case State.WANDER: if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadius) { ChangeState(State.WANDER); break; } currentEGG = SensingUtils.FindInstanceWithinRadius(gameObject, "EGG", blackboard.CloseEggDetectedRadius); if (currentEGG != null) { ChangeState(State.GO_TO_EGG); break; } currentEGG = SensingUtils.FindRandomInstanceWithinRadius(gameObject, "EGG", blackboard.FarEggDetectedRadius); if (currentEGG != null) { ChangeState(State.GO_TO_EGG); break; } currentSEED = SensingUtils.FindInstanceWithinRadius(gameObject, "SEED", blackboard.CloseSeedDetectedRadius); if (currentSEED != null) { ChangeState(State.GO_TO_SEED); break; } currentSEED = SensingUtils.FindRandomInstanceWithinRadius(gameObject, "SEED", blackboard.FarSeedDetectedRadius); if (currentSEED != null) { ChangeState(State.GO_TO_SEED); break; } break; case State.GO_TO_SEED: if (pathFeeder.target.tag != "SEED") { ChangeState(State.WANDER); break; } currentEGG = SensingUtils.FindInstanceWithinRadius(gameObject, "EGG", blackboard.CloseEggDetectedWithSeedRadius); if (currentEGG != null) { ChangeState(State.GO_TO_EGG); break; } if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadiusToItem) { ChangeState(State.BRING_SEED); break; } break; case State.GO_TO_EGG: if (pathFeeder.target.tag != "EGG") { ChangeState(State.WANDER); break; } if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadiusToItem) { ChangeState(State.BRING_EGG); break; } break; case State.BRING_SEED: currentEGG = SensingUtils.FindInstanceWithinRadius(gameObject, "EGG", blackboard.CloseEggDetectedWithSeedRadius); if (currentEGG != null) { ChangeState(State.GO_TO_EGG); break; } if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadius) { ChangeState(State.WANDER); break; } break; case State.BRING_EGG: if (SensingUtils.DistanceToTarget(gameObject, pathFeeder.target) <= blackboard.CloseEnoughRadius) { ChangeState(State.WANDER); break; } break; } }
public override bool Check() { customer = SensingUtils.FindInstanceWithinRadius(store, "CUSTOMER", 30); return(customer != null); }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.PIVOT_STATE); break; case State.SEED_POO: GameObject otherPoo; otherPoo = SensingUtils.FindInstanceWithinRadius(gameObject, "POO", myBlackBoard.farPooDetectionRadius); if (otherPoo != null && !otherPoo.Equals(targetedPoo)) { if (DistanceFromMe(otherPoo) < DistanceFromMe(targetedPoo)) { targetedPoo = otherPoo; fsm_RouteExec.Exit(); fsm_RouteExec.ReEnter(); fsm_RouteExec.target = otherPoo; } } if (targetedPoo != null && CheckIfDustInCloseRange() || CheckIfDustInLargeRange()) { /*GameObject dustOnTheWay; * dustOnTheWay = SensingUtils.FindInstanceWithinRadius(gameObject, "DUST", myBlackBoard.closeDustDetectionRadius); * if (dustOnTheWay != null) * { * if (!CheckIfDustIsInMemory(dustOnTheWay)) * { * myBlackBoard.AddToMemory(dustOnTheWay); * } * }*/ if (CheckIfDustInCloseRange()) { myBlackBoard.AddToMemory(targetedDust); targetedDust = null; } if (CheckIfDustInLargeRange()) { myBlackBoard.AddToMemory(targetedDust); targetedDust = null; } } if (targetedPoo != null && DistanceFromMe(targetedPoo) < myBlackBoard.pooReachedRadius) { CleanUp(targetedPoo); ChangeState(State.PIVOT_STATE); break; } break; case State.PIVOT_STATE: if (CheckIfPooInCloseRange() || CheckIfPooInLargeRange()) { ChangeState(State.SEED_POO); break; } else if (myBlackBoard.memory.Count > 0) { ChangeState(State.SEED_DUST_IN_MEMORY); break; } else if (CheckIfDustInCloseRange()) { ChangeState(State.SEED_DUST); break; } else if (CheckIfDustInLargeRange()) { ChangeState(State.SEED_DUST); break; } else { } break; case State.SEED_DUST: if (CheckIfPooInCloseRange() || CheckIfPooInLargeRange() && DistanceFromMe(targetedDust) > myBlackBoard.dustReachedRadius) { targetedDust = null; ChangeState(State.SEED_POO); break; } GameObject otherDust; otherDust = SensingUtils.FindInstanceWithinRadius(gameObject, "DUST", myBlackBoard.closeDustDetectionRadius); if (otherDust != null && !otherDust.Equals(targetedDust)) { if (DistanceFromMe(otherDust) < DistanceFromMe(targetedDust)) { targetedDust = otherDust; fsm_RouteExec.Exit(); fsm_RouteExec.ReEnter(); fsm_RouteExec.target = otherDust; } } if (targetedDust != null && DistanceFromMe(targetedDust) < myBlackBoard.dustReachedRadius) { CleanUp(targetedDust); ChangeState(State.PIVOT_STATE); break; } break; case State.SEED_DUST_IN_MEMORY: if (nearestDust != null && DistanceFromMe(nearestDust) < myBlackBoard.dustReachedRadius) { RemoveDustFromMemory(nearestDust); CleanUp(nearestDust); if (myBlackBoard.memory.Count > 0) { ChangeState(State.SEED_DUST_IN_MEMORY); break; } else { ChangeState(State.PIVOT_STATE); break; } } break; } }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.WANDERING); break; case State.WANDERING: if (blackboard.hunger >= blackboard.hungerTooHigh) { cheese = SensingUtils.FindInstanceWithinRadius(gameObject, "CHEESE", blackboard.cheeseDetectableRadius); if (cheese != null) { // announce the presence of cheese globalBlackboard.AnnounceCheese(cheese); ChangeState(State.REACHING_CHEESE); break; } // there's no cheese around but maybe someone has announced some if (globalBlackboard.announcedCheese != null) { cheese = globalBlackboard.announcedCheese; ChangeState(State.REACHING_CHEESE); break; } } // no transition has fired. Stay in the state. Hunger increases blackboard.hunger += blackboard.normalHungerIncrement * Time.deltaTime; break; case State.REACHING_CHEESE: // cheese is "higly volatile". It may vanish. if (cheese == null || cheese.Equals(null)) { // if it has vanished just forget about it and wander again ChangeState(State.WANDERING); break; } if (SensingUtils.DistanceToTarget(gameObject, cheese) < blackboard.cheeseReachedRadius) { ChangeState(State.EATING); break; } // no transition has fired. Stay in the state. Hunger increases blackboard.hunger += blackboard.normalHungerIncrement * Time.deltaTime; break; case State.EATING: // remember, cheese is highly volatile. it may "disappear" if (cheese == null || cheese.Equals(null)) { // if it has vanished just forget about it wander and wander again ChangeState(State.WANDERING); break; } if (blackboard.hunger <= blackboard.hungerLowEnough) // am I satiated? { ChangeState(State.WANDERING); break; } // there's cheese and I'm not still satiated... // mouse bites cheese at blackboard.bitesPerSecond rate if (timeSinceLastBite >= 1 / blackboard.bitesPerSecond) { Bite(cheese); blackboard.hunger -= blackboard.cheeseHungerDecrement; timeSinceLastBite = 0; } else { timeSinceLastBite += Time.deltaTime; } break; } // end of switch }