Over the past week or so (when I've had some spare time) I've been trying to create some basic Steering Behaviours in Lua. So far, I have Seek, Pursue and Arrive working, and hopefully in the next few days I'll have Evade, Flee & Wander. After that, I'm going to try to implement some basic Obstacle Avoidance.
To use these behaviours, it's simply a case of setting a few Variables in "onInit", and then calling the required Behaviour:
- Code: Select all
function onInit ( objID )
ai_obj = objID;
rayID = physics.createRay ( );
AI_NONE = true;
ai_movtForce = 5.0;
ai_maxForce = 10.0;
ai_mass = 75.0;
ai_arrivalDistance = 20.0;
ai_arrivalStop = 5.0;
ai_pursueObj = entity.getIDFromTag ( "mZirax" );
ai_pursueWeight = 0.9;
aiPursue ( );
aiArrival ( );
end
As you can see above, the Behaviours can have "weights" attached to them for when you have multiple Behaviours at the same time (i.e. "pursuing" one entity, while "evading" another).
For the technically minded, the code I've used is based on the Steering Behaviours from Panda3D (modified BSD Licence) as that was the best C++ version I could find.
Once I've completed these Steering Behaviours, I have plans to implement a few other AI bits & pieces in Lua (mostly from the book "Learning Game AI Programming with Lua" by David Young), such as:
Behaviour/Decision Trees
Blackboard
FSMs
Knowledge Based Reasoning
and maybe:
Neural Networks
Genetic Algorithms
As you can probably tell, I'm a bit of an "AI nerd"
Obviously, all these functions will be relatively slow in Lua, but they can easily be converted to C++ later
Regards
Shando
PS: I'll provide my code once I've got Flee, Evade and Wander working