So I have this map way in the back of my closet that has been on my mind. It is a third person top down wasd movement, mouse targeted shooter with a cover system incorporated; hiding behind things means bullets might not hit you. Its 4 players vs AI. So players are hopefully smart enough to use the cover, but what about the enemy soldiers? Currently they just stand where ever they are placed and shot mindlessly.
So what I want is to develop a combat AI system that will control each solider so they act in a combat intelligent and challenging manner. This will make the game 10X more enjoyable. If you have played rimworld, the AI in that is like what I need.
What I want:
Soldiers to hide behind cover properly, on the opposite side of the players and within firing range
To use and react to thrown grenades
Possibly do flanking maneuvers
To interact with each other, ex. charging together,
To have their combat intelligence based on their unit type Ex. a spec ops will be more likely to use cover and dodge grenades than a regular grunt
Possible commander units that increase the coordination of all nearby units and their combat intelligence
I already have some rough ideas of how to go about these things but have never tried my hand at an AI and wanted some input
Here's an extremely artful depiction of what I want for the basic cover system
You could place points behind barriers, and instruct them to move to the closest point on their side of the field. You could also have some mini regions and when multiple players leave that region, they are probably charging, and have the unit follow in that direction.
Like everything AI, it is likely a lot harder to do well than you could possibly ever imagine.
You will want to divide it into two parts. A global think loop which manages overall tactics and a per-unit tactical think loop which manages actual soldier movements and things.
A good start would be to get them to cover. In your tactical think loop you look if there are any hostiles nearby. If there is then you want to run and find cover. This can be done by hard-coding cover points into a list and then searching for the most optimum. Another more resource intensive approach might be to do a outward going search from the unit to look for "shaded" areas and flag those as cover points. Either way it will be quite resource intensive as you will need to run tests to know if a cover point is safe from the players or not. Once they found a cover point, they run towards it and they can be set as in a "taking cover" state.
When in a taking cover state if there is no global attack order they wait a random delay and move into clear shot of the player and shoot at them. If there is a global attack command they wait until the specified time (determined at a global loop level so it syncs with other units) to go out and attack. Periodically they need to evaluate if their cover is still safe from the players, if not then they need to find new cover.
If suitable cover cannot be found (eg, surrounded by players in all directions) they need to "kamikaze", since they will be shot to buggery they try to do as much damage as possible to the players.
Grenades leave some form of area marker which the unit tactical loop can evaluate to see if the unit is inside. If it is then run away from the centre, possibly entering kamikaze mode, or find a new safe cover to use.
Surrounding tactics is done at a global level by instructing units to head to cover which more evenly spaced around the player in a circle. The global loop would have to instruct the tactical loop to move the units to a specific, more strategic, cover position. The tactical AI could be given a state such as "positioning" to represent this.
Certain AI state transitions and tests could be disabled based on unit type or randomly to represent random levels of intelligence. For example militia solders might not be subjected to strategic repositioning yet normal soldiers are. Or some zombie like gunner might never take cover and rather always kamikaze the player. Without an officer some soldiers might fail to spot grenade throws and so take no action to avoid them.
Do not expect the AI to be perfect. All you can try to do is add more states and tests to make it more human like.
Thanks for the feedback. I know AI is difficult, if it wasn't we'd probably be extinct by now. I'm currently using invisible units to represent cover. My thinking is along the same lines as yours, but instead of hard coding cover points, I'm thinking search for invisible cover units in range, select one at random, generate sample points in a circle (maybe 8 or so) around the cover point, determine which is farthest from the player's unit and run there. That point should be on the opposite side of the cover of the player.
I'm thinking to save resourcing to have regions attached to each player unit (each player will only have the one) and periodically check in that region for enemies, run the cover system on any that are found.
I might do grenades by having grenades place a buff on units near them which makes them run, not sure how to incorporate combat intelligence into that way though.
For their combat intelligence I'm thinking assign each unit type a value out of 100 and any action (cover, grenade flee) will just have that percent chance of happening, or a % based off that number.
Hey so I got this working fairly well with the system I explained above. Refined it and now it just detects possible covers, finds the point on the opposite side of the nearest hostile, and sends the covering unit there if it's path able.
There's an issue I know I'm going to run into however and that is travel distance. Currently units will consider any cover point within a circle the size of the engagement range I set for that unit type. The problem is they might find a cover across a canyon or wall or something, that might be 6 distance as the crow flies, but to run around to it is more like 30 distance. So I need a condition that says target point is less than X, but I have no idea how to measure movement distance.
So: I need to measure movement distance or travel distance.
I've found the path display triggers, which have an option for measuring travel distance, have not been able to get these working at all though and don't know if it will solve my problem. The only work around I can think is send out extremely fast test units from the cover unit to the cover point, measure the time it takes them to get there, divide by whatever to get the distance. Seems really sloppy and annoying to implement. So does anyone know how I could do this?
There is a native to test distance between points. As long as both source and destination point is path-able it will work. The returned result is an approximation so might not be shortest distance, assumes a unit with 0 collision size and may have other sources of error.
So I have this map way in the back of my closet that has been on my mind. It is a third person top down wasd movement, mouse targeted shooter with a cover system incorporated; hiding behind things means bullets might not hit you. Its 4 players vs AI. So players are hopefully smart enough to use the cover, but what about the enemy soldiers? Currently they just stand where ever they are placed and shot mindlessly.
So what I want is to develop a combat AI system that will control each solider so they act in a combat intelligent and challenging manner. This will make the game 10X more enjoyable. If you have played rimworld, the AI in that is like what I need.
What I want:
I already have some rough ideas of how to go about these things but have never tried my hand at an AI and wanted some input
Here's an extremely artful depiction of what I want for the basic cover system
You could place points behind barriers, and instruct them to move to the closest point on their side of the field. You could also have some mini regions and when multiple players leave that region, they are probably charging, and have the unit follow in that direction.
New to the Editor? Need a tutorial? Click Here
Want data assets? Click Here
Like everything AI, it is likely a lot harder to do well than you could possibly ever imagine.
You will want to divide it into two parts. A global think loop which manages overall tactics and a per-unit tactical think loop which manages actual soldier movements and things.
A good start would be to get them to cover. In your tactical think loop you look if there are any hostiles nearby. If there is then you want to run and find cover. This can be done by hard-coding cover points into a list and then searching for the most optimum. Another more resource intensive approach might be to do a outward going search from the unit to look for "shaded" areas and flag those as cover points. Either way it will be quite resource intensive as you will need to run tests to know if a cover point is safe from the players or not. Once they found a cover point, they run towards it and they can be set as in a "taking cover" state.
When in a taking cover state if there is no global attack order they wait a random delay and move into clear shot of the player and shoot at them. If there is a global attack command they wait until the specified time (determined at a global loop level so it syncs with other units) to go out and attack. Periodically they need to evaluate if their cover is still safe from the players, if not then they need to find new cover.
If suitable cover cannot be found (eg, surrounded by players in all directions) they need to "kamikaze", since they will be shot to buggery they try to do as much damage as possible to the players.
Grenades leave some form of area marker which the unit tactical loop can evaluate to see if the unit is inside. If it is then run away from the centre, possibly entering kamikaze mode, or find a new safe cover to use.
Surrounding tactics is done at a global level by instructing units to head to cover which more evenly spaced around the player in a circle. The global loop would have to instruct the tactical loop to move the units to a specific, more strategic, cover position. The tactical AI could be given a state such as "positioning" to represent this.
Certain AI state transitions and tests could be disabled based on unit type or randomly to represent random levels of intelligence. For example militia solders might not be subjected to strategic repositioning yet normal soldiers are. Or some zombie like gunner might never take cover and rather always kamikaze the player. Without an officer some soldiers might fail to spot grenade throws and so take no action to avoid them.
Do not expect the AI to be perfect. All you can try to do is add more states and tests to make it more human like.
Thanks for the feedback. I know AI is difficult, if it wasn't we'd probably be extinct by now. I'm currently using invisible units to represent cover. My thinking is along the same lines as yours, but instead of hard coding cover points, I'm thinking search for invisible cover units in range, select one at random, generate sample points in a circle (maybe 8 or so) around the cover point, determine which is farthest from the player's unit and run there. That point should be on the opposite side of the cover of the player.
I'm thinking to save resourcing to have regions attached to each player unit (each player will only have the one) and periodically check in that region for enemies, run the cover system on any that are found.
I might do grenades by having grenades place a buff on units near them which makes them run, not sure how to incorporate combat intelligence into that way though.
For their combat intelligence I'm thinking assign each unit type a value out of 100 and any action (cover, grenade flee) will just have that percent chance of happening, or a % based off that number.
Hey so I got this working fairly well with the system I explained above. Refined it and now it just detects possible covers, finds the point on the opposite side of the nearest hostile, and sends the covering unit there if it's path able.
There's an issue I know I'm going to run into however and that is travel distance. Currently units will consider any cover point within a circle the size of the engagement range I set for that unit type. The problem is they might find a cover across a canyon or wall or something, that might be 6 distance as the crow flies, but to run around to it is more like 30 distance. So I need a condition that says target point is less than X, but I have no idea how to measure movement distance.
So: I need to measure movement distance or travel distance.
I've found the path display triggers, which have an option for measuring travel distance, have not been able to get these working at all though and don't know if it will solve my problem. The only work around I can think is send out extremely fast test units from the cover unit to the cover point, measure the time it takes them to get there, divide by whatever to get the distance. Seems really sloppy and annoying to implement. So does anyone know how I could do this?
There is a native to test distance between points. As long as both source and destination point is path-able it will work. The returned result is an approximation so might not be shortest distance, assumes a unit with 0 collision size and may have other sources of error.
Damn how'd I miss that >< thanks man it seems to be working.