Stealth Cover System

Made in Unity as a portfolio piece in about 12-15 hrs, with scripting done in C#

I love stealth games. They're one of my favorite genres, and I find myself missing the older style of 3rd person stealth games, like early Metal Gear Solid and Splinter Cell. I'm always toying around with the idea of making one (Ripped Pants at Work doesn't quick scratch the itch) so I thought I'd get a feel for it by making a little prototype of a cover system.

Goal

To make a 3rd person stealth cover system. The kind where you stick to the wall and you shimmy left or right. You can move around corners and you can break away at any time. However, a lot of my inspirations require a button press to go into and out of cover and move around corners. I want this system to be seamless. The player should enter cover just by pressing up against the wall and exit cover just by pushing away. Go around corners just by shimmying into them.

How It Works

Finding cover itself is fairly simple. There's a raycast firing every frame in the direction of the player's movement. Once the raycast hits a wall, the player is in cover! They do not need to press a button to enter cover. It just automatically works. When the raycast hits a wall, the player snaps to the point of the raycast's collision with the wall. The raycast itself is only as long as the player's X scale divided by 2, so the snap is not noticeable. While on the wall, the raycast continues to fire every frame to check if the player is still within cover distance of the wall.

Every frame while on the wall:

  • The player's WASD input is received by the input manager.
  • The character is snapped to the raycasted position on the wall to ensure they don't walk through it.
  • The input vector is rotated so that the player's down input matches the wall's normal direction. This way, walking to the left or right shimmies the player smoothly along the wall's surface.

While moving on the wall, two more raycasts fire, looking for corners:

  • A raycast fires in the shimmy direction looking for inside corners.
  • A raycast fires opposite of the shimmy direction, and back a little, looking for outside corners.
  • If a corner is detected, the player is snapped to the raycast point on the new wall.

Also while on a wall, the camera slerps to a position in front of the player, facing the wall, and raised a little. When off the wall, the camera behaves like a standard 3rd person camera.

If the player directs their input away from the wall, the character seamlessly snaps off and returns to default, not-on-wall movement.

What's Cool About This?

I think this cover system is great! When I'm sneaking away from guards, especially in higher stress situations, I want entering and exiting cover to be as seamless and smooth as possible. This cover system works for exactly that. Additionally, it is completely dynamic, which can save development time, as developers don't need to add cover markers on walls.

Caveats

Speaking of cover markers, there may be some down sides to having a dynamic cover system. The system could put the player in cover on objects that aren't intended to be cover, though this could be solved with collision layers. Another potential issue would be funky architecture. For any special architecture, the programmer may need to go in and write code for special use cases. Additionally, this cover system fires a few raycasts every frame. In a more simple game this would probably be fine, but I could see the desire for a less intensive cover system in a more intensive game.

In Conclusion

This was great practice! Stealth game ideas are spinning in my mind, which I feel is a sign of a great prototype.

Previous
Previous

Gilded Eternal (in progress)

Next
Next

Dilating Rifle System