TopDownMovement
namespace Griff.Scenes;
public sealed class TopDownMovement : ComponentA top-down player with no code: moves in eight directions (or four) with WASD, the arrow keys, the D-pad or the stick, never faster diagonally, with an optional dash. It ignores gravity, so it works in a game that has some. Plays its Animation’s Idle and Run clips if it has them (and IdleUp, IdleDown, RunUp and RunDown, facing that way). Needs a Body and a collider. On an isometric Tilemap, turn on Isometric so it walks over the diamonds.
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.
Controllable
Section titled “Controllable”public bool Controllable { get; set; }Untick it (from a script, in a cutscene) to ignore the player’s input. Its Focus action ticks it and unticks it on everything else the player plays (a board, another character), and back.
public bool Dash { get; set; }The Dash action (Left Shift, K or the gamepad’s B) bursts the way it’s moving, or facing.
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.
Facing
Section titled “Facing”public Vector2 Facing { get; set; }The way it last moved, as a unit vector: down to start with.
FlipSprite
Section titled “FlipSprite”public bool FlipSprite { get; set; }Flip its sprite to face left or right as it moves (art should face right).
FourWay
Section titled “FourWay”public bool FourWay { get; set; }Only up, down, left and right: for grid-like games. The way pressed last wins. With Isometric, the four ways are along the diamonds’ edges instead: up goes up to the right, right down to the right, down down to the left and left up to the left, and two ways held together go that way on the screen.
IsDashing
Section titled “IsDashing”public bool IsDashing { get; }True while it’s dashing.
Isometric
Section titled “Isometric”public bool Isometric { get; set; }Walks over an isometric map’s ground (a Tilemap whose Shape is Isometric): up and down go half as fast on the screen as left and right, as the ground is seen at a slant, so up and right together run along the diamonds’ edges. Speed is how fast it goes across the screen.
public float Speed { get; set; }World units per second.
Methods
Section titled “Methods”SetupNote
Section titled “SetupNote”public override string? SetupNote()On an isometric map with Isometric off, a reminder to turn it on.
Events
Section titled “Events”Dashed
Section titled “Dashed”public event Action<TopDownMovement>? DashedRaised at the start of each dash.