Skip to content

Latest commit

ย 

History

History
115 lines (84 loc) ยท 2.83 KB

File metadata and controls

115 lines (84 loc) ยท 2.83 KB

๐Ÿ•น๏ธ Universal 2D Player Controller for Unity

A modular, feature-rich 2D platformer player controller built on Unityโ€™s Rigidbody2D system. This controller supports both simple and advanced mechanics โ€” including jumping, dashing, wall sliding, ledge grabbing, crouching, and more โ€” making it ideal for any 2D platformer game.


๐Ÿš€ Features

  • โœ… Basic Movement with acceleration & deceleration
  • ๐Ÿฆ˜ Jumping with coyote time & buffering
  • ๐ŸŒฌ๏ธ Air Control with custom gravity handling
  • ๐Ÿงโ€โ™‚๏ธ Crouching with ceiling detection
  • ๐Ÿงฑ Wall Slide & Wall Jump
  • ๐Ÿง— Ledge Grab & Climb
  • โšก Dashing with cooldown and direction control
  • ๐ŸŒ€ Double Jump (optional)
  • ๐ŸŽž๏ธ Animation & Visual Effect Hooks
  • ๐Ÿ”Š Sound Events for jump, dash, and land
  • ๐Ÿง  UnityEvent Support for plug-and-play reactions
  • ๐Ÿ› ๏ธ Highly configurable from the Unity Inspector

๐Ÿง  Setup

  1. Import the Script
    Add UniversalPlayerController.cs to your Unity project.

  2. Attach Required Components

    • Rigidbody2D
    • Collider2D (Box, Capsule, etc.)
    • UniversalPlayerController
  3. Configure Settings
    Tweak values like speed, jump power, gravity, and toggle optional features (dash, crouch, wall jump, etc.).

  4. Assign Optional Components

    • Animator
    • Audio Clips
    • Particle Systems
    • Transforms for ledge/ground/ceiling detection

๐ŸŽฎ Default Input Mapping

Action Input Key
Move Left/Right A / D or Arrow Keys
Jump Space
Crouch S or Down Arrow
Dash Left Shift
Climb / Drop (Ledge) W / S or Arrow Keys

๐ŸŽจ Animator Parameters (Optional)

The controller updates these Animator parameters:

  • Grounded (bool)
  • Speed (float)
  • InputSpeed (float)
  • Crouch (bool)
  • WallSliding (bool)
  • LedgeHang (bool)
  • VerticalSpeed (float)
  • Dashing (bool)
  • Dash (trigger)

๐Ÿงช Unity Events

Subscribe to the following UnityEvents in the Inspector:

  • OnJump
  • OnLand
  • OnDash
  • OnWallJump
  • OnLedgeGrab

๐Ÿงฐ Public API

player.SetMaxSpeed(float newSpeed);
player.SetJumpPower(float newPower);
bool grounded = player.IsGrounded;
bool dashing = player.IsDashing;
Vector2 velocity = player.Velocity;

๐Ÿ“‚ Suggested Folder Structure

/Scripts/Player/UniversalPlayerController.cs
/Prefabs/Player.prefab
/Animations/PlayerAnimator.controller
/Audio/Jump, Land, Dash.wav
/Particles/JumpFX, LandFX, DashFX

๐Ÿ“„ License

This project is licensed under the MIT License.


๐Ÿ™‹โ€โ™‚๏ธ Contributions Welcome

Bug reports, improvements, and pull requests are appreciated. Let's make 2D platformers better together!