0Pricing
Lua Academy · Lesson

Movement and Collisions

Make a playable scene.

Position and Velocity

Movement in LÖVE means changing an object's position over time. Store x and y, then add velocity in love.update scaled by dt.

Keeping velocity as dx and dy per second makes diagonal motion and physics clean and frame-rate independent.

function love.update(dt)
  player.x = player.x + player.dx * dt
  player.y = player.y + player.dy * dt
end

Input-Driven Movement

Combine polling with velocity to steer an object. Read direction keys in love.update and apply speed times dt.

Because love.keyboard.isDown is checked every frame, the player moves smoothly while the key is held.

function love.update(dt)
  if love.keyboard.isDown('left') then player.x = player.x - player.speed*dt end
  if love.keyboard.isDown('right') then player.x = player.x + player.speed*dt end
end

All lessons in this course

  1. The LOVE Game Loop
  2. Drawing Shapes and Images
  3. Handling Input
  4. Movement and Collisions
← Back to Lua Academy