Movement

See also: collision

System: input

The basics:

  • user input
  • character key frame animation
  • position on screen

Moving left – then flipping the direction

Movement is context based – for example, the background moves when in an ‘over world’ type map (such as map in LTTP), but not necessarily if you are in a small room which will totally fit with the game screen (like links house in the opening scene from LTTP)

For TOP DOWN style games

4 directions – constant movement

always respond to current key that is being pressed (the ‘last key’ pressed

if (keys.w.pressed && lastKey === ‘w’) background.position.y += 3

keys.w.pressed = true

            lastKey = ‘w’

4 directions – turn-based movement (rogue-like style)

determine if you can move there – then animate the char there – see porklike movement for an example

8 directions

Examples

  • Zelda: A link to the past
    • moves in 8 directions
    • sprites for 4 directions
  • Earthbound
    • moves in 8 directions
    • spites for 8 directions

easing?

calculate vector

apply vector

no gravity

moving in 8 directions

Platformer

Hang time

GODOT

 var input_vector = Vector2.ZERO

input_vector.x = Input.get_action_strength(“ui_right”) – Input.get_action_strength(“ui_left”)

input_vector.y = Input.get_action_strength(“ui_down”) – Input.get_action_strength(“ui_up”)

JS

 – is there a clean and simple solution for this?

//Move the cat and keep it inside the boundaries

cat.x = Math.max(0, Math.min(cat.x + cat.vx, canvas.width – cat.width));

cat.y = Math.max(0, Math.min(cat.y + cat.vy, canvas.height – cat.height));

velocity/easing in/out

usually applied to movement, but could be for anything really

snap to pixel

Movement correction

“While Link can move a single pixel at a time, in any direction, the longer he continously moves in any direction the more he gravitates toward aligning himself with the underlying grid of the screen. The tile grid for LoZ is 16 tiles wide by 14 tiles high (including 3 tiles for the status display at the top of the screen). Each tile is 16×16 pixels. Link operates on a half-tile grid, though (32×28 tiles, 8×8 pixels each). As Link moves, if he’s not currently aligned with the half-tile grid, he is adjusted, one pixel at a time, toward the closest correction. As a result, if Link is 4 pixels off alignment he’ll line back up with the grid after moving 4 pixels.” – from https://troygilbert.com/deconstructing-zelda/movement-mechanics/#:~:text=The%20tile%20grid%20for%20LoZ,8%C3%978%20pixels%20each).

This is somewhat the case in Earthbound too…

For SIDE ON  ‘mario’ style games

has gravity

fixed ‘x’ position or not fixed (a range)

jump in ‘y’ position

Sub-pixel (fixed-point number) movement – ala mario 3

(1 pixel is divided into 16 sub pixels)

Store values and do calculations using sub-pixels – then convert to screen coordinates for rendering…

Celeste

Resources