For when an NPC had free time I decided to implement a finite state machine. I chose this method mainly for simplicity, I knew in the short term this would be a quick and easy way to do things. However if I add many more states in the future it might be best to switch to a behaviour tree instead.
void freeTime(){
if(dnc.hours <= 9 || asleep){
destination = ps.home.transform.FindChild("Rug").gameObject;
}
else {
if (doneFree){
doneFree = false;
freeTimeAction = Random.Range(0,5);
}
switch(freeTimeAction){
case 0:
getFood();
break;
case 1:
goToBestFriend();
break;
default:
goHome();
break;
}
}
}
As you can see there are only states at this stage. Once the getFood() state is performed the state can transition to either goHome() or goToBestFriend(). Going to best friend than then transition into going home only if it's time for bed.
This current implementation might be limited, but it can be easily adapted for more complex behaviours if required in the future.
No comments:
Post a Comment