designing scripted AI for a game
My project is an RPG. I want to implement AI using Lua scripts, and I use the following approach:
Each entity has a refresh interval, that is, every 1.5 seconds (aprox.) the entity is refreshed, life and mana regenerated and a Lua script is executed. The script will do actual AI: wander around, mumble things, if fighting, will call appropriate routines to check life level and select attacks, etc. Other events like entity being touched (selected) by player, attacked and so are handled by a different script triggered when the event occurs.
Is that design right? Or perhaps there is a more optimal way?
Typically you'll want to update the AI much more often, say at least 10Hz. Otherwise your AI will be too unresponsive for periods of time... (You can't rely on your event handlers only.)
You can do this by using Lua's coroutines to execute in the background, or just design your main AI update() to be called more often.
Apart from that, it sounds sensible!
You can do this by using Lua's coroutines to execute in the background, or just design your main AI update() to be called more often.
Apart from that, it sounds sensible!
Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!
I looked at coroutines, but didnt found how to use them. Also I was thinking to move AI to a separate thread, but I still dont know how to properly manage that.
In the same way that you'd have varying levels of detail when rendering graphics, your AI should be dynamically scalable as well. Characters that aren't in the player's vicinity do not need to update as often or as accurately. Don't fix you update interval, rather, have the interval determined by the proximity of the character to the player. Also, make sure the low frequency updates are staggered so the load is spread more evenly.
As for multithreading, it's not an easy thing to implement. You could update AI in a separate thread, but the synchronisation is going to be difficult. Alternatively, you could use a job system whereby the non-main game threads process jobs from the AI, such as path finding, i.e. AI creates request to find path from current position to target, when thread finds a result, the result is sent back to the AI generating the request and the AI's state is updated. Of course this could mean the AI gets smarter at finding routes as more processors are added to the system which in turn leads to gameplay balancing issues.
Skizz
As for multithreading, it's not an easy thing to implement. You could update AI in a separate thread, but the synchronisation is going to be difficult. Alternatively, you could use a job system whereby the non-main game threads process jobs from the AI, such as path finding, i.e. AI creates request to find path from current position to target, when thread finds a result, the result is sent back to the AI generating the request and the AI's state is updated. Of course this could mean the AI gets smarter at finding routes as more processors are added to the system which in turn leads to gameplay balancing issues.
Skizz
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement