Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
U

Unity-2D-Platformer-Controller

> 编程语言
Open source

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dr

992 stars0 likes1 views
WebsiteGitHub

About

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dr

Unity 2D Platformer Controller

=======================

A customizable 2D platformer motor that handles mechanics such as double jumps, wall jumps, and corner grabs. Includes a player controlled prefab that can be dropped into any scene for immediate support.

Obtain!

Releases

If you'd like the most up to date version (which is the most cool), then pull the repo or download it here and copy the files in Assets to your project's Assets folder.

NOTE!!!!

Unity 5.3 appears to change the behavior of ray/boxcasts which PC2D relies heavily on. Make sure Environment Check Distance and Minimum Distance From Env need to be increased from what they were in Unity 5.2 (default is 0.08 and 0.04). This isn't a perfect solution but allows it to work within Unity's physics system.

Also I am no longer using the platformer controller in my own personal projects so it's not getting the personal testing it deserves. Please open up an issue if there are any problems.

Setup

For immediate player support, drop the Basic Player Controller prefab into the scene and set the Static Environment Layer Mask field. For more complicated interaction, interface with PlatformerMotor2D's members and methods.

Upgrading

When upgrading take a note of your current motor values before upgrading. There is no guarantee made that variables names won't change and if they do then the old values will be lost in the inspector.

Requirements of PlatformerMotor2D

BoxCollider2D

The motor requires that a Collider2D be present on the GameObject. The motor uses the bounds of the Collider2D to understand where to check for contact with surfaces.

PlatformerMotor2D Inspector Properties

General

Static Environment Layer Mask - This tells the motor what layer collisions to consider the environment (to determine if on the ground, wall, or corner). These are environments that shouldn't be able to move into the player.

Environment Check Distance - This is how far out the motor will check for the environment.

Minimum Distance From Env - This is the minimum separation between the motor and surrounding environnment. This is used to prevent catching matching edges of box colliders (or tiles). Half distance of the Environment Check Distance is probably pretty good.

Number of Iterations - The number of iterations the motor can take to resolve the final position during a tick. Lower numbers mean more performant but at a cost of potential position loss. 2 iterations will likely cover most cases (unless the time step is really long).

Enable for One Way Platforms - Should the motor check for one way platforms? Uncheck this if there aren't any, the motor will be more efficient. This will only have an effect if the motor's collider can't collide with its own layer. If it can then setting this to false won't help, one way platforms or not.

Moving Platform Layer Mask - What layer contains moving platforms. The motor uses this knowledge to grab a MovingPlatformMotor2D component from the platforms. This requires that 'Raycasts Start in Colliders' is true in the Physics 2D settings. If there aren't any moving platforms then make sure this value is 'Nothing' (or 0). The motor will be more efficient.

Additional Raycasts Per Side - By default the motor will raycast through the corners to separate itself from moving platforms (or static environment if moved into one by a moving platform). The raycasts can miss if the environment is small enough. Increasing the number of additional raycasts can fix this issue. A good way to think about it is if the smaller environment is at least the size of the motor then this can be 0. Half the size of the motor then it should be 1. A third then 2 and so on. Caution as more raycasts are more expensive.

Movement

Ground Speed - Maximum ground speed.

Time to Ground Speed - The time, in seconds, it will take to reach ground speed. This is used to calculate acceleration. A value of 0 mean instantaneous movement.

Ground Stop Distance - If at full speed, how far will the motor skid to a stop.

Allow Direction Change In Air - If true, then the motor's x velocity can be changed while in air. If false, then the motor's x velocity cannot be changed when in the air.

Air Speed - Maximum speed the motor will move horizontally while in the air.

Time to Air Speed - The time, in seconds, it will take to reach air speed. This is used to calculate acceleration.

Air Stop Distance - If at full air speed, how far will the motor 'skid' to a stop.

Fall Speed - Maximum fall speed (only y axis when negative).

Gravity Multiplier - Gravity multiplier to the Physics2D.gravity setting. Works like RigidBody2D's gravityScale.

Fast Fall Speed - Maximum fall speed when falling fast.

Fast Fall Gravity Multiplier - Gravity multiplier when falling fast.

Jumping

Jump Height - The height, in Unity units, that the motor will jump to.

Extra Jump Height - If the motor is informed that the jump is held then this is the additional height the character will jump.

Air Jumps Allowed - This sets the number of air jumps the character is allowed to perform. Setting it to 0 will disable air jumping altogether.

Jump Window When Falling - The time in seconds that a jump will be allowed after it become invalid. This would be like allowing a jump even though the player has technically walked off the edge. Setting this to a low value (such as 0.1) can feel like a better experience for the player. If undesired then just set to 0.

Jump Window When Activated - How long the motor should remember that Jump() was called and activate a jump if it becomes valid in that time. This means that a player could press jump before they actually hit the ground and the motor will allow it to occur.

Slopes

Enable Slopes - Should the motor check for slopes? If there aren't any slopes to walk/up down or slide down then uncheck this. The motor will be more efficient.

Angle (Degrees) Allowed For Moving - This is the degree of the slope the motor can walk on. 0 means only on flat ground where as 50 would mean any slope up to and including 50 degrees.

Change Speed on Slopes - Should the motor slow down on steeper slopes. The speed is based off of Max Ground Speed and the angle of the slope. If false then the motor always moves at Max Ground Speed on any allowed slope.

Speed Multiplier on Slopes - Multiplier against the speed on slopes. This will heavily emphasize slow downs on slopes.

Stick to Ground - This tells the motor to try to always stay on the ground when moving down slopes or up over slopes. For example, if this is false and the motor moves forward on a plane that then slopes down, the motor will fall onto the slope. If this is true then the motor will stay connected to the ground.

Ground Check Distance for Sticking - The motor ray casts down to see if there is ground to stick to. This value tells the motor how far to check. Increase this if the motor isn't sticking properly. Be cautious having this value too large as it may make the motor stick to grounds that aren't intended.

Wall Interactions

Enable Wall Jumps - If jumping off the wall is allowed.

Wall Jump Multiplier - The base jump speed is calculated from Base Jump and Extra Jump Height. The multiplier multiplies the result. Leave at 1 for no change.

Wall Jump Angle (Degrees) - The angle (in degrees) of the wall jump. 0 is along the wall normal and 90 is straight up.

Enable Wall Sticks - If the motor should stick to walls.

Wall Stick Duration - The time, in seconds, that the motor will stick to walls. A large value (say 1000000) is effectively infinite.

Enable Wall Slides - If the motor should consider any wall sliding calculations. Wall sliding is when the character would slow down while 'sliding' down the wall.

Wall Slide Speed - The speed that the character will slide down the wall.

Time to Wall Slide Speed - The time, in seconds, it takes for the character to go from 0 to Wall Slide Speed.

Enable Corner Grabs - If corner grabbing is allowed.

Corner Grab Duration - The time, in seconds, that the motor will stick to corners.

Corner Jump Multiplier - The multiplier on a corner jump from the calculated speed.

Corner Distance Check - A corner is considered grabbed if the upper corners of the collider do not intersect with the environment but the sides do. The value changes the consideration for box checks dimensions.

Ignore Movement After Jump Duration - How long the motor should ignore horizontal input movement after a wall jump or corner jump. This can allow better feeling wall jumps.

Valid Normalized Interaction Area - This is the size of a valid check (normalized to collider height) that will consider wall interactions valid. Starts from the top of the collider and moves down.

Wall Interaction Threshold - The input threshold for wall clings, corner grabs, and slides. Could be set to higher to prevent unwanted sticking to walls.

Wall Interaction Cooldown - Cooldown for allowing slides, clings, and corner grabs. This may be necessary if the motor can slide down a vertical moving platform. If they don't exist then this can be 0.

Dashing

Enable Dashes - Is dashing allowed?

Dash Distance - The distance covered by the dash.

Dash Duration - The duration of the dash.

Dash Cooldown - How long, in seconds, before the motor will allow dash again?

Dash Easing Function - The easing function of the dash. For a dash that movement with a consistent speed pick linear.

Gravity Delay After Dash - The delay, in seconds, before gravity is reenabled after a dash. This can allow a short pause after an air dash before falling.

PlatformerMotor2D Members

csharp
float normalizedXMovement

Set the x movement direction. This is multiplied by the max speed. -1 is full left, 1 is full right. Higher numbers will result in faster acceleration.

csharp
float timeScale

Set the time scale for the motor. This is independent of the global time scale. Negative values are not supported.

csharp
Vector2 Velocity

The velocity of the motor. This should be queried instead of the rigidbody's velocity. Setting this during a dash doesn't have any meaning. NOTE: Setting rigidbody2D.velocity can have unexpected results. If you want to let Unity Physics take over then disable the motor first.

csharp
MotorState motorState // Readonly

enum MotorState
{
    OnGround,
    Jumping,
    Falling,
    FallingFast,
    WallSliding,
    OnCorner,
    WallSticking,
    Dashing,
    Frozen,
    Slipping
}

Call this to get state information about the motor. This will be information such as if the object is in the air or on the ground. This can be used to set the appropriate animations.

csharp
CollidedSurface collidingAgainst // Readonly

[Flags]
public enum CollidedSurface
{
    None = 0x0,
    Ground = 0x1,
    LeftWall = 0x2,
    RightWall = 0x4,
    Ceiling = 0x8,
    SlopeLeft = 0x10,
    SlopeRight = 0x20
}

State information on what the motor believes itself to be colliding against. These are flags so any number may be turned on.

csharp
bool facingLeft

The direction the motor is facing.

csharp
bool onSlope // Readonly

If the motor is currently on a slope. This will be true for walking up/down slopes as well as slipping down a slope.

csharp
bool slopeNormal // Readyonly

The normal of the slope the motor is on. This only has value if onSlope is true. This value could be used to calculate up/down the slope for movements such as dashes.

csharp
bool fallFast

Set this true to have the motor fall faster. Set t

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言