🎮

Creating a First-Person Shooter in Unity

Oct 31, 2024

First-Person Shooter Game in Unity Series

Introduction

  • Creating a first-person shooter (FPS) game in Unity.
  • Features include:
    • Shooting different guns
    • Picking up weapons and ammo
    • Reloading weapons
    • Aim Down Sights (ADS)
  • Generic weapon script for customization in other games (open world, survival, etc.).

Course Structure

  • Fast-paced for those already familiar with Unity.
  • Beginners can join but will not cover basic concepts in-depth.

Episode Breakdown

  • Episode 1: Project Setup and Basic Movement
    • Creating a 3D Universal Render Pipeline (URP) game using Unity 2022.1.23.
    • Organizing project folders (settings, scripts, etc.).

Creating the Player Environment

  • Create a plane (ground) for the player to stand on.
  • Create an empty object named "player" and add a character controller.
  • Add a cylinder as the player's body and adjust the scale.

Player Movement Scripts

  1. Mouse Movement Script

    • Set mouse sensitivity, x rotation, and y rotation.
    • Lock cursor in start method.
    • Get mouse input:
      • Mouse X: left/right movement
      • Mouse Y: up/down movement
    • Rotate body based on mouse movement.
    • Implement clamping to limit rotation:
      • Top limit: 90 degrees
      • Bottom limit: -90 degrees
    • Use public float for clamping to allow inspector adjustments.
    • Move main camera to the player's head position.
  2. Player Movement Script

    • Define variables: speed, gravity, jump height, ground check, velocity, grounded state, last position.
    • Reference character controller in start method.
    • Use physics check sphere to determine if the player is grounded.
    • Reset velocity when grounded and adjust for jumping.
    • Get input for player movement directions (x and z axes).
    • Move player using character controller's move method.
    • Implement jumping logic with gravity application.
    • Track grounded state to prevent infinite jumps.

Implementing Ground Check

  • Create an empty object for ground check and attach to player.
  • Set ground mask and create ground layer (apply to the plane).

Testing

  • Confirm player can move, jump, and look around.

Next Episode

  • Focus on shooting mechanics.
  • Call to action: Subscribe for future updates.