Skip to content

SiddDevCS/UnityCustomPlayerMovement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Player Movement Script for Unity

This script provides first-person movement for a player using the CharacterController component in Unity. It includes:
โœ”๏ธ Basic movement (WASD)
โœ”๏ธ Sprinting with limited stamina
โœ”๏ธ Dynamic Field of View (FOV) changes when sprinting
โœ”๏ธ Gravity simulation
โœ”๏ธ Stair detection and smooth climbing


๐ŸŽฎ Features

  • Smooth First-Person Movement: Uses Unity's CharacterController for smooth motion.
  • Sprinting with Stamina: Sprint depletes over time and regenerates when not in use.
  • Realistic Gravity: Keeps the player grounded and prevents floating.
  • Stair Climbing: Detects stairs and allows smooth vertical movement.
  • FOV Adjustment: Field of View increases while sprinting for a more immersive feel.

๐Ÿ“œ How to Use

  1. Attach the Script: Add the PlayerMovement script to the player GameObject in Unity.
  2. Add Components: Ensure the player has:
    • A CharacterController component.
    • A Camera attached as the player's view.
    • A Ground Check empty GameObject under the player.
  3. Configure Variables: Adjust movement speed, sprint duration, FOV values, and gravity in the Inspector.

๐ŸŽฎ Controls

Action Key
Move W A S D
Sprint Left Shift
Look Around Mouse

๐Ÿ› ๏ธ Setup in Unity

  1. Create an Empty Object under the player:
    • Name it GroundCheck and position it at the player's feet.
    • Assign it to the groundCheck variable in the script.
  2. Set up Layers:
    • Add a "Ground" layer and assign it to ground objects.
    • Add a "Stairs" layer and assign it to stair objects.
    • Set groundMask to Ground and stairsMask to Stairs in the script.
  3. Ensure the Player Has a CharacterController component.

About

Playermovement for my horror game :)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages