0

I'm trying to plan out a cover system for a 3D game.

The mechanic

  1. When the player approaches a surface they can take cover behind...
  2. A prompt appears indicating they can enter cover, and what to press to do so.
  3. If the player presses the prompted button, their avatar is locked into a path following the scenery they're taking cover behind.
  4. If the cover is a half wall, the avatar should crouch.
  5. If the player approaches a gap in cover the camera should peek around the corner and
  6. ...they should be prompted to jump to the next cover
  7. ...otherwise, the player can exit cover by pressing another action button.

As seen from directly overhead (please forgive the side view character):

Figure depicting cover mechanic

The plan so far

As far as I know, cover must be either

  • baked into the level by algorithm
  • explicitly created by the level designer
  • somehow handled on the fly

What I think should happen is the environment should be baked into hidden geometry which qualifies as cover. Then, I would detect sphere collisions (blue) with the generated cover areas (purple) to find out when one is in range.

Figure depicting cover detection

Static geometry would qualify as cover if it were higher than a certain amount from adjacent ground (ie. at least 2.5 feet tall), and another threshold would indicate whether the character should crouch (at least 6 feet for standing cover, otherwise crouch). It seems like this would also be helpful for NPC vision and path finding.

This sphere detection process could be used similarly to locate gaps with cover available on the other side. Finally, once in cover, the player would move tangent to the cover surface (purple regions). Cover surfaces with angles less than a certain threshold would interpolate the current path into the path the player should follow to continue, otherwise they would be counted as a corner. So when the player reaches the end of cover, the angle of the adjacent surface determines that cover has ended and will prevent the player from accidentally breaking cover. They could press a button to move around the corner.


But I prefer not to reinvent the wheel - so is this "correct," or is there some accepted way of doing this that's totally different?

jzx
  • 3,805
  • 2
  • 23
  • 38

1 Answers1

1

Avoid using an algorithm for figuring out cover from the raw environment, you'll have to debug both the algorithm and the environment when the character decides to snap through another object and then gets stuck or fall through the floor, or 5 crates in a slight L placement cause the algorithm to make a huge cover box rather than a proper L, etc.

Handling this on the fly is even worse for this as you'll have a harder time reproducing the bugs.

Best is to have cover boxes attached to entire cover objects (tipped tables, walls, windows, stone wall) that are instantiated in the environment and other explicitly created cover boxes for groups of random props (crates) that the level designers can control.

Make sure you can visualize the cover boxes for debugging and also have a tool check for invalid placement such as two covers too close to another that will snap the player into the other collision so they can then be fixed by hand.

Any game logic that snaps actors into place (ledge grab, cover, sitting in chair, etc) are a huge source of collision bugs, be ready to spend a surprising amount of time debugging those.

Stephane Hockenhull
  • 11,962
  • 1
  • 25
  • 44