Advice on spaceship combat AI (3D)

Started by
13 comments, last by ApochPiQ 8 years ago

Yep, utility is a great way to do this, although many other techniques can be applicable as well. The hardest part is turning the input data (ship positions, orientations, velocities, health, etc.) into something you can recognize patterns in.

From a technical sophistication standpoint, you can do this with a lot of different methods, but the simplest and easiest is to just write a bunch of rules down. If the ships match this one situation, fire this AI scene in response; and so on. Evaluate the rules in priority order (i.e. write the if() statements in order of highest-priority to lowest) and you're done.

At the top end of the spectrum you could do it with all kinds of pattern recognition algorithms, but that's probably overkill unless you want to spend a lot of time building the AI.

Utility is kind of a sweet spot of "easy to calculate individual pieces" and "easy to combine those pieces of data into meaningful pattern detection."

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement

Ok so just to sum up my understanding of it all

I have a manager that know every ship in the scene (including the player but ofcs it wont issue commands to the player). The manager also has info to all aspects of the ship (e.g. health, velocity, direction vector/orientation, do i still have missiles)

I will have a list of actions that i want to launch which i could either pick based on scoring each of them for the current situation or just by a list of ifs based on the situation(as you mentioned)

Some of these actions might be do an attack run on a capital ship, get close to any enemy fighter you wanted to target and fire some rounds (could come from behind or from the top etc) or do a dodge maneuver/ dodge incoming fire (life take a hard left).

One might be where one ship wants to dog fight another when the manager rules might say (really basic)

  • if 2 ships on other teams are close to each other
  • chose one to attack the other
  • fire while the other ship takes the fire
  • do allow collision avoidance/separation

These behaviors can have allowances like allow collision avoidance and separation. I could also instead have a bidding system where ships bid curtain actions.

The only logic the ships themselves would do is steering behaviors and rotation. If i was to have bids this would be done too.

The manager can use all ships on the scene to do actions that it wants to do. in every tick the manager should make sure that either a ship has been used for an action or is currently in progress of doing an action.

With all this I can have the manager play different scenes for what is happening in the battle based on the rules and actions I have.

This fixes my original 2 problems as no 2 ships will try and chase each other and end up hitting each other as the managers actions i specify would never allow this or the other problem where one ship will just feel and take hits easy hits as i could desire for that ship to take hits (either because it is doing something else or i have told it to) or i can give it an option to do an maneuver so it dodges (i will have to work out some logic to see which one i want to do).

Anything i have missed?

Thank you very much for the time and help ApochPiQ.

Sounds like you're on the right track! Feel free to poke the thread if you run into any difficulties.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Hey ApochPiQ, after fixing some problems with the player movement, I finally have time to work on the manager and if you don't mind i just have a couple more questions about some areas.

I have decided my manager is going to be based on scoring different set actions that ships can do (looping through every ship). For example I will have the following for fighters

  • Target an enemy ship and hit (targeting will be done on another level of scoring)
  • Target an enemy ship and the enemy evades (i will have a list of manoeuvres which will be a projection of seek points relative to the ships position)
  • Target an enemy bomber and hit (targeting will be done on another level of scoring)
  • Target an enemy bomber and the enemy evades
  • Target an enemy capital ship and hit
  • Target an enemy capital ship and die
  • Fire missile on enemy ship (targeting will be done on another level of scoring)
  • do a two pronged attack on an enemy ship

so for most of these I can score by the following

  • distance from each target
  • dot product/angle between my forward vector and distance between vector
  • health of capital ship/number of turrents it has left
  • number of missiles
  • is a friendly unit near me
  • my current HP

Each ship will have a boolean to state if it is free, each tick, the manager will go around and make sure every ship is doing something and set that bool to false (im doing something)

Each behaviour has a set time that it happens for.

So i only have two more questions

  1. what is the best way to score if we should hit of missing the target, im guessing i could base it how the fight is going to give advantages but i would prefer another determining factor.
  2. say one ship is already attacking or fleeing/dodging another (flee will just be done when the target will get hit and a manoeuvres is done for dodging) is it a problem at all to target that ship (with this I would say that the behaviour that would win is Target an enemy ship and hit as its not trying to dodge but since the other ship is still doing something it wont matter to it)
  3. or (in relation to 2) If a ship is free and it targets an enemy ship that is already doing something should I make it so it resets its behaviour to the new one

Ofcourse 2 and 3 will not be a concern when targeting the player :)

Anyone else feel free to chip in if you want to

Cheers for the help in advance

1. You can easily just toss a coin, or do a weighted random to bias towards one team, or whatever; it doesn't have to be complex. A simple but powerful trick for this is to use a response curve - a function that goes from (0,0) to (1,1). You feed in an X value of time, and the (Y value - 0.5) gives you a bias towards one team or another. Positive is one team winning, negative is the other team. This can be used to get "tension" or "near escapes" or whatever just by tuning the function.

2/3. If a ship is already busy, there are two rules you obey: (1) it cannot be placed into a maneuver unless the score of the maneuver is higher than the score of whatever it is currently doing. (2) If you don't need to control the ship's position, such as for a "fighter scores a hit on enemy fighter" event, then the ship can be in multiple "events" at once.


Hope that's helpful!

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement