3D Game AI in WebGL and Javascript

Posted on:March 13 2013

Programming artificial intelligence for games, aka Game AI usually is a challenge. And if you are limited by CPU, lines of code, memory and even the programming language itself, it quickly isn't that fun anymore. I just released a free update of CopperCube, version 4.0.3, which includes an update to the included Game AI behavior. If you ever used it, you know that it is very basic, but with this new update, I made it a bit smarter and a bit more tweak-able. But see for yourself, in this WebGL demo:

Both game AIs in this demo only use 20 KB of JavaScript code to do what they do: One AI is instructed to try to go along a path forming a circle around the room, while the other one is set to 'randomly patrol'. Both are set to hate each other, so attack each other. I've not given them any weapons, but they don't know this: They still will try to fire at each other. What this demo tries to show is that the AI doesn't know anything about the obstacles in the room, so they blindly stumble around in the area, but try to keep at least their countenance up a bit. If you would have tried this with the previous version of the AI in CopperCube, this would have looked pretty ridiculous.
The same AI behavior is of course also available if your publish your app as Android app, Windows .exe or Flash .swf file: It uses the same minimal amount of code on all platforms, so it runs very quickly everywhere. As most game "AI"s, there is a simple state machine behind it. Thus calling it "AI" is a bit exaggerated. In this case, the AI has just 4 high level states ("do nothing", "reach position", "attack item" and "die and stop"), and based on the situation, it will switch between the states.
In this CopperCube update, the AI has been tweaked so that it can handle obstacles better, and the user now is also able to set waypoints where the AI is supposed to go. Also, specify how long the AI should wait once it reached its target position is possible now. With this, it should be easier to create nicer games, I hope. But of course: The AI still can be improved a lot. And it is no comparison to the AI in modern games. But it is a start. :)





Comments:


I don't know why, but it somehow made me think of "boids":http://www.red3d.com/cwr/boids/
xaos
Quote
2013-03-14 11:09:00


Yes, me too :)
niko
Quote
2013-03-14 11:52:00


Add comment:


Posted by:


Enter the missing letter in: "?nternational"


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons