I didn't have many issues implementing the routines into the movement of the NPCs, although prioritizing certain activities over others if there is a time clash doesn't work as I would like to expect.
For each cycle of the void Update() method:
foreach(RoutineEntry re in ps.routine){
//If task is within start and end hour and it hasn't been done
if ((dnc.hours >= re.startHour) && (dnc.hours < re.endHour) && (!re.done)){
//They are not free
free = false;
freeChk = false;
//change destination to the location of the routine entry
destination = re.location;
p = destination.transform;
//If the type of routine is visit
if (re.type == 'V'){
if (Vector3.Distance(p.position,transform.position) < 2){
//Consider it done once a certain distance has been met
re.done = true;
}
}
}
}
This means the current routine the NPC performs is never saved, each cycle the appropriate action is applied depending on the time of day, and if the RoutineEntry is done or not. This has a few comparisons to that of a behaviour tree. The biggest advantage being that NPCs will immediately react to a change in their routine. However in it's current form RoutineEntries at the beginning of the foreach loop with have a higher priority. In the future I could set a priority to each RoutineEntry and sort the list accordingly each time a routine is added to an NPC schedule. This would solve this issue, and give the NPCs more control.
No comments:
Post a Comment