JavaScript MMORPG – Maiu Online #babylonjs – Ep: 25 – Monsters AI System

JavaScript MMORPG – Maiu Online #babylonjs – Ep: 25 – Monsters AI System

Finally I finished work on first prototype of monsters AI module. Monsters have several states: IDLE, PATROL, DEAD, FLEEING, COMBAT.
Idle monsters are non active even when someone attack them. Patrolling ones are walking around and checking each 0.5s is they have someone to attack in a range if yes then they start chase target (combat state) and attack when in range. Dead are obvious and fleeing is triggered when monster is enough far away from the position where it switched into combat state.
I also added death to the monsters after 120s they respawn.
Implementation have some bugs and AI it’s just bunch of ungly if’s but It enables further development and testing. I will go back to this after some time and try to impove it.

From the technical point of view it’s designed in a way that monsters service is independent from the main engine loop. It can be deployed on separate machine, I hope this will very significantly unload main engine in the future, I’ll be able to afford very inefficient AI implementation without compromising game performance.
Monsters are pretty much like players but are not connected by websocket’s proxy but by internal api(redis pub-sub in future, right now I’m working on the mock for simplicity but have prepared redis and mocked implementation).
Monsters service keep replicated state of the whole simulation and ‘AI agent’ is responsible for handling all monsters logic.

Hope You like it!

Discover more from Coursity

Subscribe to get the latest posts sent to your email.


No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *