FPS Advance player movement mechanics

Опубликовано: 10 Апрель 2026
на канале: GameAdda
43
0

Welcome to Part 3 of our FPS player movement series! In this video, we'll be covering some advanced movement techniques such as jumping and crouching. These are essential mechanics that will add fluidity and depth to your player's movement, and they’re key components in most FPS games.If you missed the earlier parts of the series, be sure to check out the links in the description below. And don't forget to hit that like button, subscribe, and ring the notification bell so you never miss a tutorial!

1. Variables
•crouchHeight: This is the height the player will shrink to when crouching.
•standingHeight: This is the height the player will be at when standing. •jumpHeight: The height the player will reach when they jump.
•gravity: The force of gravity that will pull the player down when they’re not grounded.
•jumpSmoothness: Controls the smoothness of the jump by influencing how the Y position is interpolated.
•isJumping: A flag that tracks whether the player is currently jumping.
•isGrounded: A flag to check if the player is on the ground.
•isCrouching: A flag that tracks whether the player is crouching.
•verticalVelocity: This controls the vertical movement (used for jump and fall).
•originalYPosition: The player’s initial Y position (ground level).
•targetYPosition: The target Y position the player wants to reach during the jump.
2. Jumping Logic
•HandleJumping(): This function is responsible for handling the player's jump and gravity. It checks if the player is grounded and presses the jump button (Space). It also handles the fall speed when the player is not jumping.
◦If the player is grounded and presses Space, the jump begins by calling StartJump().
◦If the player is jumping, the Y position of the player is smoothly updated using Mathf.Lerp(), which creates a smooth interpolation between the current Y position and the target Y position (targetYPosition).
◦The vertical velocity is updated to simulate gravity when the player is not jumping.
◦When the player’s Y position reaches the originalYPosition (ground level), the player is marked as grounded, and vertical velocity is reset.
•StartJump(): This function is called when the player starts a jump. It: ◦Sets isJumping to true.
◦Defines targetYPosition as the current position plus the jump height (jumpHeight).
◦Resets verticalVelocity to 0 to ensure the jump starts from a clean slate.
3. Crouching Logic
•HandleCrouching(): This function checks if the player presses the crouch button (LeftControl). If the player is not jumping, it toggles between crouching and standing.
◦If the player is crouching, they will stand up (restore height to standingHeight).
◦If the player is standing, they will crouch (set height to crouchHeight). ◦The height transition is done smoothly using a coroutine (ResizePlayerHeight).
•ResizePlayerHeight(float targetHeight): This coroutine smoothly changes the player’s height over a period of time.
◦It stores the current height and the target height.
◦It uses Mathf.Lerp() to smoothly transition from the current height to the target height over 0.25f seconds.
◦After the transition, it updates the isCrouching flag based on whether the target height is the crouch height or standing height.
4. Key Mechanics Explained
•Smooth Jumping: The use of Mathf.Lerp() in HandleJumping() helps the player’s jump feel smoother by interpolating the Y position between the current position and the target position (targetYPosition).
•Gravity Effect: When not jumping, gravity is applied by adding a vertical velocity (verticalVelocity) that increases over time, causing the player to fall. This is a simple gravity simulation.
•Crouch Transition: The player’s height is smoothly changed using Mathf.Lerp() inside the ResizePlayerHeight coroutine, allowing for a fluid transition between standing and crouching.

Part 2 :    • FPS Player Movement Tutorial #unitygamedev...  
part 1 :    • Creating Realistic FPS Camera Movement in ...  

#gameadd154 #fpsplayermovement #advancedmovementtutorial #jumpcrouchmechanics #playerjumpscript #crouchmovement #fpscrouchtutorial #gamedevelopmenttutorial #unityfpstutorial #smoothjumping #gamephysics #fpsmechanics #unityplayermovement #fpsmovementseries #playerjumpheight #crouchtoggle #gamedevelopment #unitytutorial #smoothplayerjump #playermovementinunity #fpscontroller #jumpsmoothness #unitycrouchmechanic #smoothcrouch #crouchandjumpunity #fpsjumpmechanics #playerjumplogic #unityplayerjump #advancedfpsmovement #gamemovementsystem #unityphysicstutorial #playercrouchsystem #fpsmovementscript