# How to use game world clock, calendar and random offsets in Utility AI?

This topic is 460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Let's say I have a bunch of NPCs that need to go to work every weekday. There will be additional considerations for cases when they would choose to stay home (low health etc.).

So, the basic logic is as follows:

Behavior "GoToWork", should be considered only if it's Monday to Friday AND only if clock time is after 6:00 AM, applying random shift of up to 3 hours to prevent all NPCs rushing out at the same time.

The world clock and calendar is knowledge base and I can map clock (minutes) to input range. But days and random shifting are not that straight forward. I could map minutes for entire week as a single input and build a custom piecewise curve with sharp transitions (because it's essentially yes/no decision - I don't want to consider it at night or on Sundays at all) and use that as the second consideration for GoToWork.

But still I'm not sure how it is supposed to be implemented "the right way" with utility AI. Which condition checks belong where and how to add that random offset for each NPC separately?

##### Share on other sites

This has very little to do with utility AI... of any AI for that matter... and more about knowledge representation. For the most part, it can be solved by Programming 101 sorts of answers.

• Create a representation of what a day is.
• Create a function for determining that.
• Create another boolean function for "is it a weekday" that checks to see if the day returns M-F.
• Create a representation for what time of day it is.
• Create a boolean function for whether or not it is a work hour or not.

if (IsItWeekday && IsItWorkHours) { GoToWork(); )

##### Share on other sites

Oh, I see, yes, I can fall back to boolean inputs for considerations for cases when I clearly need opt-in / opt-out.

I guess, my brain switched into curves mode and failed to think in simple booleans; or maybe I felt that boolean considerations are evil in utility AI because of being too strict and breaking the "fuzzy logic" feeling of it

##### Share on other sites

I use them all the time and encourage them. There are some things that simply make sense that way. For example, if you have a stealthy action that you only want to do when you are invisible, you can do a boolean check to see if you have the "invisible" tag. If you don't, the behavior is automatically 0 (since the consideration is 0) and you move on.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 18
• 35
• 9
• 16
• 22