How to make a cover system like R6 ?

Hi everyone , i making a game and i want make a cover system like rainbow six vegas 2,
this is the cover system at 00:01:00

.

I think this script is good but i do not know how to do the cover system .

function Update()
{
     if(Input.GetKeyDown("f"))
        {
            if(Vector3.Distance(cube.transform.position, transform.position) < 3)//Detect if the player can cover
              {
              Joueur.position = Vector3(cube.position.x -2,cube.position.y,cube.position.z);//Teleport the player next to                                                                                                                                            the wall
            contrelemur = 1; //Into the wall in french
            //And the cover system
              }
        }
}

Well , if you can help me , i give you chocolate pie , not a chocolate cake !

Up please ?

Hi,

There are three parts to cover systems:

  • Cover Detection: Is the player in a valid location to take cover?
  • Animation: Positioning the player and playing the cover animation.
  • Control State: The actions available to the player are usually different when in cover – such as blind firing, leaning, etc., but not running, jumping, etc.

Cover Detection
This is typically done either at design time or run time.

To do it at run time: When the player presses “f”, run a short raycast from the player. If it hits an object, the player can take cover behind it. Better yet, run several raycasts. Lateral (left/right) raycasts let check for cover that might be at a slight angle from the player. Vertical (up/down) raycasts make sure that the object provides sufficient cover from head to toe. Run time detection is more expensive because of the raycasts, and may allow the player to take cover in inappropriate places, but it’s easier to set up.

At design time, the designer can add trigger colliders to areas that provide cover. When the player enters the trigger, record that he’s in a cover area. When he exits the trigger, record that he’s no longer in a cover area. When the player presses “f”, you already know whether he’s in a valid cover area or not, so you don’t need to perform expensive raycasts. Another advantage of design-time cover specification is that you can include additional information in each trigger, such as the specific animation to play for this cover area, the value of this cover (so the AI can decide which is the best cover area to move to), whether anyone is already using this cover trigger, etc.

Animation
As you can see in the video, the player plays a specific animation to turn around and crouch down. You need to know what animation to play. For basic cover, you can play the same animation. But if he’s dashing toward the box you might want to play a special “sliding into cover” or “diving into cover” animation instead.

In addition, he aligns his transform to the box. You’ll probably want to use a raycast for this, and align the player’s transform to the raycast normal. (If any of these terms don’t make sense, read up on Physics.Raycast.)

Control State
In cover, the player’s actions and camera control are usually different. When in cover, you could disable the primary control script and enable a different control script that only allows in-cover actions such as blind firing, sneaking sideways in cover, etc. Also, in this script, the “f” key should probably make the player exit cover.

The same idea applies to camera control.

Enabling and disabling scripts is a quick-and-dirty way to change control state, but it would probably be better to use something like a finite state machine (FSM) to switch between control modes.

1 Like

As a better replacement for raycasting to detect walls: Unity - Scripting API: Physics.CapsuleCast

I prefer overlapSphere and tags, if the tag is true, it finds the normal, then use Lerp or vector3.movetowards to move in direction of the normal.

A.Killingbeck and Kinos141 bring up good points. There are lots of ways to detect objects, and it’s worth your time to consider which is the best for your case. For cover, I prefer Physics.Raycast because you can spot check at several points to make sure you have some coverage at feet, knees, and hips. If you instead ran a single Physics.CapsuleCast, it might detect something tiny like a ping pong ball and think that you can take cover behind it.

While that may be true with capsulecas, I would give all cover areas a tag called “cover wall” that would be checked against.

A more performance friendly method would be to put all cover objects on their own layer and only cast against that layer. Solves your “tiny ping pong ball” issue as well.

2 Likes