Hello everyone
I was am currently making a dogfight game and the major problem that is troubling me is the AI.
I even checked GBRausers by @britzl and was amazed
Still, I was actually thinking about creating an AI like this Dogfight 2.
I am never good at programming AI, so I request to please help me out.
The AI seems to be fairly simple. The enemy planes will obviously always move/fly in the direction they are facing and they will always try to rotate towards the player.
I have an example of how zombies rotate and move towards a player here: https://github.com/britzl/publicexamples/tree/master/examples/simple_ai
The code should be directly translatable to your project. Relevant snippet of code: https://github.com/britzl/publicexamples/blob/master/examples/simple_ai/simple_ai/zombie.script#L27-L38
The example is really cool(including the zombies!) . But the major problem that I come across is that when you have more than 1 plane, they all tag behind one another creating a nice crowd of planes.I really liked how it was solved in Dogfight 2 and wanted to implement it in my game.
Not sure I got the right game (I didnāt want to install flash, so watched this instead.
One way to avoid crowds is to check if other planes are nearby.
You can add a collision object specifically for this, and make it a bit bigger than the plane, and make it detect other enemy planes.
And when they start to move too close to each other, you can make them either keep their distance, or move them further apart etcā¦
This is a good suggestion. I played around with this solution a bit this evening. It can probably be tweaked for better results:
CODE: https://github.com/britzl/publicexamples/tree/master/examples/swarm_ai
DEMO: http://britzl.github.io/publicexamples/swarmai/index.html
Many many Thanks to @britzl and @Mathias_Westerdahl for your help. After thinking over it for a month, at last I got what I desperately needed.
Just one more doubt-How do I increase the radius in which the swarm ai ships are rotating(could be helpful when dealing with multiple ship types.).
P. S. Thanks again
That would be a combination of rotation speed:
And movement speed:
High rotation speed and low forward speed and youāll turn on the spot. Low rotation speed and high forward speed and youāll need a huuuge radius to turn.
Nice! Please share a playable when you have the time!
This is actually something Iāve worked on in C++. I donāt a DLL for my ānav controllerā object, but maybe I should.
a) Is there a place to get a ātemplate library dependency projectā somewheres?
b) It can also help if you modify a planeās turn speed slightly (adding fractions of a unit, like a random number 0-40 X 0.001 or something when the planes are created) so that they donāt all fly exactly the same way. Does your dogfighting plane have turn speed?
Creating a library project is only a matter of specifying which folder(s) you wish to export in game.project. Check the manual on library projects for more info.
@britzl While playing around with your AI, I noticed one thing though. If the enemy is killed, all the other enemies on the screen stop and the console throws an error instance null not found while calculating distance to. So, do I have to do something like table.delete on nearby table or probably something else am I missing?
But I must add that your AI is awesomeā¦
Well, I would suggest that your code sends a message to each AI agent when their target dies. And if they donāt have a target they can roam randomly or continue to travel in their current direction.