GridMovement
Steps tile by tile with no code, for puzzle games, roguelikes and old-school RPGs: as a player, each press of WASD, the arrow keys, the D-pad or the stick moves it one cell of the scene’s Tilemap, gliding there over StepTime, and holding a way keeps it walking. Solid tiles, solid colliders and other grid movers block it (it turns to face them instead). It starts on the middle of the cell it’s placed in. Plays its Animation’s Idle and Walk (or Run) clips if it has them (and IdleUp, WalkDown and so on, facing that way). Needs a Body and a collider, so pickups, doors and damage reach it; it ignores gravity. With a GridChase or a GridPatrol it’s an enemy or another mover instead, stepping on its own; with a Pushable it’s a crate that grid movers push a cell at a time by stepping into it. WalkTo (or its Destination) walks it to a cell, the nearest free one of several, or an entity, round walls and other movers: workers, villagers, units sent somewhere. On an isometric map it steps from diamond to diamond: 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 (with Diagonal, every way pressed goes that way on the screen). On a hex map it steps from hexagon to hexagon, six ways: left and right along the row, up or down with left or right held to the hexagon up or down that side, and up or down alone zigzagging straight up or down the screen.
Requires: Body; Collider
Works with: Tilemap (steps on its grid, blocked by its solid tiles); Animation (plays Idle and Walk clips); GridChase (steps after a target on its own: an enemy); GridPatrol (walks a route of cells on its own); Pushable (a crate pushed a cell at a time)
Needed by: BumpAttack, GridChase, GridPatrol, TacticsUnit
Takes the player’s input only while it has focus (its Controllable): its Focus action hands it the input and takes it from everything else the same player plays.
In a network game, the player it moves for runs it on their own machine and sends where they are.
Properties
Section titled “Properties”Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.
map: text = null. The tilemap whose cells it steps between. Empty uses the first tilemap in the scene (not a layer); with none, it steps a world unit at a time, between whole-number positions. (Names an entity.) (Field: an entity’s name.)stepTime: a number = 0.15. Seconds each step takes to glide from one cell to the next. (Field: a number.)repeat: true or false = true. Holding a way keeps stepping that way. Untick it to step once per press. (Field: on or off.)repeatDelay: a number = 0. Seconds a way has to be held, after the first step, before it keeps walking: 0 walks straight on, about 0.25 lets a puzzle’s careful single steps come easily. (Only used when repeat is on.) (Field: a number.)diagonal: true or false = false. Steps diagonally too, when two ways are held. It never cuts a wall’s corner. A hex map’s six ways are all along its hexagons’ sides, so there it changes nothing. (Field: on or off.)stayOnMap: true or false = true. Never steps off the edge of its Map, even where there’s no wall. (Field: on or off.)
Control
Section titled “Control”controllable: true or false = true. Untick it (from a script, in a cutscene) to ignore the player’s input; Step still works. Something with a GridChase, a GridPatrol or a Pushable never takes the player’s input. Its Focus action ticks it and unticks it on everything else the player plays (a board, another character). (Field: on or off.)flipSprite: true or false = true. Flip its sprite to face left or right as it moves (art should face right). (Field: on or off.)
Sounds
Section titled “Sounds”stepSound: text = null. A sound played with each step, e.g. “Sounds/step.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)bumpSound: text = null. A sound played on trying to step into a wall, once per press. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
Walking
Section titled “Walking”destination: text = null. Where it’s walking to (see WalkTo): cells, as “column row” pairs separated by semicolons and counted as Cell is, e.g. “4 2; 5 2”, of which it goes to the nearest that’s free; or an entity’s name, whose cell it walks to (or next to it, when something solid is there). Empty while it isn’t walking. The game empties it on arriving; set it to send it off. (Plain text: cells or an entity’s name: Walk To and the game set it.) (Field: text.)blockingLayers: text = null. Collision layers whose solid colliders are in its way, e.g. “Obstacle, Wall”; empty for every solid collider. Solid tiles and other grid movers always are. It goes for a step as for a walk, so a walk plans round what really blocks it. (Names collision layers: their names, separated by commas.) (Field: a name.)giveWay: a number = 0.5. Seconds a walk waits, face to face with another walker that’s waiting for it (two in a one-cell aisle), before one of them steps aside to a free cell off the other’s way and lets it by: the one later in the scene, unless only the other has somewhere to go. (Field: a number.)arrivedMessage: text = null. A message sent with Game.Send when a walk gets to its Destination, with this entity as its data. (Names a message.) (Field: a name.)blockedMessage: text = null. A message sent with Game.Send each time a walk has to stop and wait (see Blocked), with this entity as its data. (Names a message.) (Field: a name.)
Actions
Section titled “Actions”What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).
WalkTo(done with a name, its place: a trigger’s with). Walks to place: cells as “column row” pairs, e.g. “4 2; 5 2” (the nearest that’s free), or an entity’s name. Empty stops it. See Destination.StopWalking. Stops walking, in the cell it’s in or stepping into.Focus. Gives its entity the player’s input: whatever there and inside it has focus, and everything else the same player plays loses it (a platformer’s player stops on the arrow keys while a board takes them).
While the game runs
Section titled “While the game runs”Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.
isWalking: true or false. True while it’s walking to its Destination, waiting on the way included.isWaiting: true or false. True while a walk is held up: another mover is in its way, there’s no way to its Destination just now, or it has stepped aside to let another by.goal: [x, y], whole numbers or null. The cell of its Destination it’s heading for now (it changes as cells fill and free up); null when it has none.facing: [x, y]. The way it faces, one cell’s step as a unit vector (diagonals are (±1, ±1)): down to start with. Like Step’s ways, it’s along the grid: on an isometric map, (0, 1) faces up to the right, and on a hex map (1, 1) faces the hexagon up to the right and (0, 1) straight up the screen.isMoving: true or false. True while it’s gliding from one cell to the next.cell: [x, y], whole numbers. The cell it’s in, or heading into while it moves: column then row on its Map, row 0 at the top (on no map, its whole-number position).stepping: true or false. True while it’s taking a step from one cell to the next.from: [x, y]. Where the step under way (see Stepping) started, in the world.started: true or false. True once it has snapped onto its grid (it does as it first runs, and again after Unplace): until then its Cell isn’t known yet.
Scripts use it as GridMovement: its methods, events and values that aren’t saved with the scene.