Playchilla logo

A goal driven bot

After some productive hours I managed to assemble a bot with a few goals, reusing some old code and adding some new.

In the example below I added four goals
1) LookAround – the head of the bot looking in random directions (visualized with the flashlight)
2) RandomWalk – the bot picks a random spot in the sandbox and move there.
3) Investigate – if the player accidentally bumps into a wall within a limited distance from the bot, the bot will hear this and the investigate goal will kick in to find out whats going on.
4) Chase – if the player is in the seeing frustum (flashlight) the bot will start to chase the player

I am trying to set up a simple model that allow the bot to run multiple goals at the same time. So for example the RandomWalk goal can run at the same time as the LookAround goal. This is managed by booking resources on the bot. E.g. LookAround only utilized the head, while the RandomWalk utilized its wheels – therefore they can run simultaneously. So basically all goals that can run at the same time are selected from a prioritized queue.


To add some flavor I made a little tag game, try tagging the bot without him seeing you, sneaking up from behind, for each successful tag a new level is generated the bot will get more vision and speed. However if the bot catches you in the flashlight the game will fall back one “level”. (USE ARROWS)

Get Adobe Flash player

Move the ball with arrows, avoid being seen by the red bots, try bumping into them from behind unseen.

Again, possible future articles:
– Goal selection
– Controlling a bot with physics (forces)
– 2D shadow casting

Not sure what to do next, perhaps drop down multiple bots and to play along in the sandbox. This usually involves making sure they don’t want to go to the same spot all the time, or collide into each other and instead not getting anywhere. Not sure if this is needed for the plan, a reactive tower defense game, but for a little shooter or so it would be cool.


    It is shaping up very nicely, with some tweaks to enemy’s movement it could be used to make a very nice Tactical Espionage game, akin to Metal Gear Solid! I sure would love to play a decent, 2D, sneaking title.

    So far I follow with the AI, I wonder how things will look later. What I am more curious about is the implementation of the line of sight, the actual drawing of the cone. Can you spill some beans about it? 🙂

    • Yes that would be cool!

      I did the drawing of the cone awhile back using drawTriangles, masking a circle with three triangles. As it turns out this is very inefficient, turning on 5 bots slows the game down when they have to render shadows. I will probably disable this until I figure out a better solution. The actual line of sight is using circle casting that is the same for testing if two bodies collide in some future time (from the physics engine I wrote some time ago). I use circle casting with the bots body size to ensure the bot can move to what he sees and don’t get stuck between two obstacles. I hope that explains the concepts?