Sponsored By
Robert Basler, Blogger

September 9, 2015

2 Min Read

(Originally from onemanmmo.com)

I've been programming for 34 years now. I have never had something like this happen before.

I was working on a feature for the AI for the units in my little RTS game The Imperial Realm::Miranda. If the AI decides to move to attack an enemy, I want it to return to its original location afterwards so units don't just wander off whenever an enemy comes by.

To implement this, after a unit is downloaded to the client, I save the unit's home position so it knows where to go back to. With an existing unit exactly nothing happens then -- just like I planned it.

A brand new unit's Y location isn't actually set to a good value when it is downloaded, (shortly after it is downloaded, some other code on the client sets the Y value to place the new unit at the right height above the terrain.) The first time the AI wakes up and looks for something to do, it sees the change in Y and as far as it is concerned, the unit has moved from its home. The AI then tries to move the unit back to its home location (where it actually is already) however, as part of the process of moving to its destination, it does a collision check to make sure that the destination it is moving to doesn't have any other units on it. If its destination is blocked it will move to the nearest clear location.

I had another feature on my task list which said:

Make new units find a good position to park instead of just appearing on top of one another in front of the war factory.

A bug in the AI does that for me now completely for free!

The first time a unit moved aside after creation I was completely astonished.

AI is voodoo.

Read more about:

Featured Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like