8
\$\begingroup\$

My question is about the data structure (and logical way to use this structure) behind this type of comportment of NPC enemy : How does he computes the place where he can take cover when the player is shooting at him ?

It can be in a FPS-like, or a "board game" view game...

\$\endgroup\$

4 Answers 4

9
\$\begingroup\$

You've got 3 main options:

Option #1: (Most robust, but most CPU Intensive)

In real-time calculate corner areas wide enough for the NPC to hide and that aren't exposed to the player. Choose the nearest for the player to hide.

This will work on any level which is nice and on levels with geometry that changes during gameplay. But it will take the longest to get working consistently and will use up to most CPU resources during the game.

Option #2: (Save level designer time, minimal real-time hit)

Create an offline tool that does the corner test and then places nodes in your level for all potential cover areas. LD's can then tweak these nodes or remove ones that aren't appropriate.

During gameplay just find the nearest valid node.

This is nice in that your corner finding routing doesn't have to be 100% accurate since LD's can screen out a few bad nodes here and there. Can't respond to changes in geometry though unless you start getting clever with attaching them to objects, or scripting them on/off.

Option #3: (Brute Force, minimal real-time hit)

Have LD's manually place all cover nodes, and then just choose the nearest valid node during gameplay.

If you have lots of levels or big levels expect the LDs to complain.

\$\endgroup\$
3
\$\begingroup\$

I think the best way to do it would be to manually set up boxes in the area(s) that you want the NPCs to take cover in.

Have a variable for "fear" or some other metric you want, when a threshold is reached the NPC should move to the closest box that is out of the players line of sight.

You could figure a way to dynamically have enemies take cover over behind any object, but more times than not those can generate some strange and illogical cover positions.

\$\endgroup\$
1
\$\begingroup\$

There is a description of how the AI of killzone searched the position space to get a good position here (PDF). You could change the evaluation function to augment the value of a cover position if the AI is shooted at, or heavily damaged. Thus AI that are not shooted at would take a little more risk to get the target.

You could also add AttackingHobbo's solution, augmenting the cover interest depending on the fear factor (ie 0 : i'm invincible / 1 : i take care / 5 please make it stop)

regards

\$\endgroup\$
1
\$\begingroup\$

Depends on the style of game. It's fairly common to let level designers place cover objects, which can be either a volume, a shape representing a covering object or a node. This is more labor-intensive for LDs but gives much more control, which is usually wanted in a tightly scripted game.

For open-world games, you need an automatic cover detection system. We used one that detected cover at runtime in Battlefield: Bad Company (1 & 2) in order to be able to invalidate and re-detect on environmental destruction.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .