PlatformerMovement
namespace Griff.Scenes;
public sealed class PlatformerMovement : ComponentA platformer’s player with no code: runs with A/D, the arrow keys, the D-pad or the stick, and jumps with the Jump action (Space or the gamepad’s A), forgivingly: a jump pressed just before landing still happens, and one pressed just after running off a ledge still counts. Letting go early makes a short hop. Turn on air jumps, wall jumps and a dash as the game needs them. It climbs Ladders and a tilemap’s ladder tiles, climbs and swings on Ropes, drops through one-way platforms on down and Jump, and plays its Animation’s Idle, Run, Jump, Fall, Climb, Dash and WallSlide clips if it has them. Needs a Body and a collider.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Acceleration
Section titled “Acceleration”public float Acceleration { get; set; }How quickly it gets up to speed, in units per second per second. 0 is at once.
AirControl
Section titled “AirControl”public float AirControl { get; set; }How much of its Acceleration and Deceleration it keeps in the air: 1 all, 0 none.
AirJumps
Section titled “AirJumps”public int AirJumps { get; set; }Extra jumps in the air before landing again: 1 is a double jump.
ClimbSpeed
Section titled “ClimbSpeed”public float ClimbSpeed { get; set; }Climbing speed on ladders, in units per second.
Controllable
Section titled “Controllable”public bool Controllable { get; set; }Untick it (from a script, in a cutscene) to ignore the player’s input; it still falls and lands. Its Focus action ticks it and unticks it on everything else the player plays (a board, another character), and back.
CoyoteTime
Section titled “CoyoteTime”public float CoyoteTime { get; set; }Seconds after running off a ledge that a jump still counts.
public bool Dash { get; set; }The Dash action (Left Shift, K or the gamepad’s B) bursts forward, once in the air until landing again.
DashCooldown
Section titled “DashCooldown”public float DashCooldown { get; set; }Seconds after a dash before the next.
DashSound
Section titled “DashSound”public string? DashSound { get; set; }A sound played with each dash.
DashSpeed
Section titled “DashSpeed”public float DashSpeed { get; set; }Dash speed, in units per second.
DashTime
Section titled “DashTime”public float DashTime { get; set; }Seconds a dash lasts.
Deceleration
Section titled “Deceleration”public float Deceleration { get; set; }How quickly it stops once let go, in units per second per second. 0 stops dead.
DropThrough
Section titled “DropThrough”public bool DropThrough { get; set; }Down and Jump on a one-way platform drops through it.
DustEffect
Section titled “DustEffect”public string? DustEffect { get; set; }A prefab spawned at its feet on jumping and landing, e.g. a puff of “Dust”.
Facing
Section titled “Facing”public int Facing { get; set; }Which way it faces: 1 right, -1 left.
FallMultiplier
Section titled “FallMultiplier”public float FallMultiplier { get; set; }Gravity is this many times stronger while falling, for a snappier jump. 1 falls like it rises.
FlipSprite
Section titled “FlipSprite”public bool FlipSprite { get; set; }Flip its sprite to face the way it’s going (art should face right).
IsClimbing
Section titled “IsClimbing”public bool IsClimbing { get; }True while it’s on a ladder or a rope.
IsDashing
Section titled “IsDashing”public bool IsDashing { get; }True while it’s dashing.
IsOnRope
Section titled “IsOnRope”public bool IsOnRope { get; }True while it hangs on a Rope, climbing it or swinging on it.
IsWallSliding
Section titled “IsWallSliding”public bool IsWallSliding { get; }True while it’s sliding down a wall.
JumpBuffer
Section titled “JumpBuffer”public float JumpBuffer { get; set; }Seconds before landing that a jump press is remembered.
JumpHeight
Section titled “JumpHeight”public float JumpHeight { get; set; }How high a full jump goes, in world units.
JumpSound
Section titled “JumpSound”public string? JumpSound { get; set; }A sound played on every jump, e.g. “Sounds/jump.wav”.
JumpsLeft
Section titled “JumpsLeft”public int JumpsLeft { get; }Air jumps it has left before landing.
LandSound
Section titled “LandSound”public string? LandSound { get; set; }A sound played on landing from a fall.
MaxFallSpeed
Section titled “MaxFallSpeed”public float MaxFallSpeed { get; set; }The fastest it falls, in units per second. 0 has no limit.
ShortHop
Section titled “ShortHop”public bool ShortHop { get; set; }Letting go of Jump on the way up cuts the jump short, for small hops.
public float Speed { get; set; }Running speed, in world units per second.
WallJump
Section titled “WallJump”public bool WallJump { get; set; }Jump while against a wall in the air to kick off it, away from the wall.
WallSlide
Section titled “WallSlide”public bool WallSlide { get; set; }Pushing into a wall while falling slides down it slowly, at WallSlideSpeed.
WallSlideSpeed
Section titled “WallSlideSpeed”public float WallSlideSpeed { get; set; }How fast it slides down a wall, in units per second.
Methods
Section titled “Methods”JumpSpeedFor
Section titled “JumpSpeedFor”public float JumpSpeedFor(float gravity)The speed a jump of JumpHeight leaves the ground at, under gravity gravity (units per second squared, as a positive number).
Launch
Section titled “Launch”public void Launch()Sent flying by something other than a jump (a Bouncer, an explosion): air jumps and the air dash come back, a dash stops, and letting go of Jump won’t cut the flight short.
Events
Section titled “Events”Dashed
Section titled “Dashed”public event Action<PlatformerMovement>? DashedRaised at the start of each dash.
Jumped
Section titled “Jumped”public event Action<PlatformerMovement>? JumpedRaised on every jump: from the ground, a wall, a ladder or the air.
Landed
Section titled “Landed”public event Action<float>? LandedRaised on landing from a fall, with how fast it was falling.