Giving senses to AI
So here we go, another Friday and another opportunity to write something up about the game.
I've been knee deep in a sensor feature of the AI this week, basically the way it works is, if I want the AI to know about it's surrounding, I want a circle which is a sensor for this area.
As Items come into the area and leave it, they are added to a list of things on the sensor.
Here's a visualization of what that looks like:
The idea comes from the fact I want some form of stealth in the game, or at least ways to sneak in some form. Here is the original design I put into the game for this, and so I've tried to follow that verbatim, i.e. make a circle, and things in that circle have been "sensed".
So the initial testing for it works, they can sense the objects inside their circle... It does this using the Physics library I'm using called MatterJS... But yknow what, after implementing it - I feel it might not be the most optimal.. Sometimes it slows down if there are too many objects in the scene.
For now i'm going to leave it in, but I've got a sneaky feeling that I will rewrite this at some point. I'll have the same functionality but be built in a different way.
Turns out I've rewritten it! It follows exactly the same rules without using Matter.js physics.
It's simple really, in the thread used for calculating states, I simple loop through rendered life objects (which is a short list) and calculate which ones are within the distances... It instantly relieved the CPU massively.
Leave a comment
Log in with itch.io to leave a comment.