A 2D platformer class for godot.
-
Updated to Godot 4.0
- Removed set and get functions in favour of properties
-
Can now have negative jump height, which will reverse gravity
-
Gravity is now positive when pointing down, and negative when pointing up
-
Added 'jumped' and 'hit_ground' signals
-
Split the large
_physics_process
function into multiple functions
- Updated to Godot 3.4
- Fixed division by zero error when changing min jump height
- Other minor fixes
- Add platformer_controller.gd to your project
- Type
extends PlatformerController2D
to the top of your script - Add these input mappings in your project settings (or you can change the input variables in the inspector)
- "move_left"
- "move_right"
- "jump"
- Double jump
- Coyote time
- Jump buffer
- Hold jump to go higher
- Defining jump height and duration (as opposed to setting gravity and jump velocity)
- Assymetrical jumps (falling faster than rising)
Here are the values that you can change in the inspector:
The max jump height in pixels. You reach this when you hold down jump.
The minimum jump height (tapping jump).
The height of your jump in the air (i.e. double jump, triple jump etc.).
How long it takes to get to the peak of the jump (in seconds).
Multiplies the gravity by this while falling.
How many times you can jump before hitting the ground. Set this to 2 for a double jump.
How much you accelerate when you hold left or right (in pixels/sec^2).
The higher this number, the more friction is on your character.
If this is off, you have to press jump down every time you land. If its on you can keep it held.
You can still jump this many seconds after falling off a ledge.
Pressing jump this many seconds before hitting the ground will still make you jump.
Note: This is only needed when can_hold_jump is off.
input_left
input_right
input_jump
Set these to the names of your actions in the Input Map