Skip to main content
GameDev.net gamedev.net
🔒 Locked

Target aquiring

Started by LlamaGuy Jan 29, 2004 at 8:21 PM 3 replies 650+ views
Original Post
LlamaGuy
LlamaGuy
I''m making a space fighter game called Myriad Argosy in C++. It''s not the Galaga type... you can move in all directions. But to the point: I don''t like my current AI system as it only allows for enemies to attack the player, they can''t attack any thing else. Here''s how it works... you''ve got a ship structure that holds everything needed about any given ship. The player''s ship is stored in it''s own structure, and every other ship is stored in a linked list. When updating enemy ships, they just go straight for the player ship. So now, instead of putting the player ship structure seperatly, I''m going to put it in with the list of ships. Each ship structure has a ''team'' field and ''priority'' field. I need to come up with an efficent way for ships to aquire targets efficently, but still work good. For example: if an enemy is attacking you (a 5 priority ship) and a colony transport floats by (a 10 priority ship) the enemy ship would go after the transport. Right now my current idea is to have a currentTarget pointer in each ship''s structure. It will attack the currentTarget regardless. Then every second or so it would reaquire targets, if it finds something of higher priority then currentTarget will repoint to the new ship. I''m accepting suggestions though because I''m looking for the most efficent design possible. --- Guns don''t kill people.................. ...........................................Lag kills people. ~LlamaGuy
krez
krez
i can''t give you any efficiency tips, but your idea sounds good to me. be sure to adjust the priorities for if a ship is damaged, or attacking an important target, though. what i mean is, there is no reason to leave off attacking a nearly destroyed ship to get a new target, when you could kill that ship in another few seconds and be rid of an enemy; or when the current target is attacking the mothership, it should remain high priority even if a transport comes by.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Timkin
Timkin
There are two questions that need to be answered here:

1) How will an NPC ship choose another ship as its target; and,
2) How will you implement this.

The latter depends very much on the former.

Ask yourself what you would do given a certain scenario. One technique is merely to encode the rules that you use to make a decision directly into the computer (often using a script system with a finite state machine). Other techniques might consider complex relationships between ships and evaluate them mathematically to determine one of possibly many ''current scenarios'', with each scenario assigned a response action.

Personally, I would think that a fuzzy state machine would give you a reasonable evaluation and state transition framework. There''s plenty of info on the web on state machines and fuzzy logic.

Good luck,

Timkin
LlamaGuy
LlamaGuy
I''m going for quickness and simplicity. I plan to have many ships active at one time, so they must be able to decide very rapidly.
jacksaccountongamedev
jacksaccountongamedev
I faced a similar situation some time ago. Basically, what I did was, for each ship, go through all the ships (or just the ships in the immediate area) and give each one (that is not on the same team as it) a value based around a few variables:

Distance.
Angle difference between our ship’s current direction and the direction between our ship and the ship in consideration.
Health.
Priority.

And more, depending on how smart you want your AI to be in this decision. Then chose the ship with the highest (or lowest, depending on how you code it) value as your target.

Now each of these variables needs to be scaled appropriately to fit into proportion with the rest, giving different variables more importance than others.

Alternatively, you might like to simply select the closest ship as the target.

Then, on the other hand, you may wish to go over the top and weigh the entire situation out, choosing targets that will permit you a strategic advantage. For instance, you may like to take into account the position of all friendly ships and the position of all enemy ships, and then chose a target that will allow you to stay close to your allies, while avoiding targets that are bunched in large groups of enemies.
Another neat trick would be to take a look at what each of our allied ships are targeting, and then make a decision based upon that. For instance, you might like to avoid targets that are already being dealt with in order to balance out the battle, or you might like to focus on such targets to promote group-killing tactics.
You could look at what each of the enemy ships are targeting and the move to help those allied ships under the largest threat.
Here is a neat one: you could have your ships jump on the opportunity to intercept and cut of an enemy craft that is being tailed by an ally. This could be done quite simply by taking the angle difference between the direction from the ally chasing and our ship and the direction from the ally chasing to the enemy ship, then adding it too the angle difference between the direction the enemy is flying and the direction from the enemy ship to us, then checking the result to see if it is below, say, 60, and if so we know that we can intercept this ship nicely and therefore make it our target. That is assuming my on-the-spot maths shills are correct. If you were to use a formula such as this you''d want to tie it in with the standard target selection routines etc.

But, then again, I am no pro at this sort of thing so don''t read this thinking that this is standard stuff. It is merely my suggestions - what I might do in a situation like such.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.