Jump to content
  • Advertisement
Sign in to follow this  
midix

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

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 :D

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!