Skip to content

Instantly share code, notes, and snippets.

@Uradamus
Created March 20, 2014 15:28
Show Gist options
  • Save Uradamus/9666386 to your computer and use it in GitHub Desktop.
Save Uradamus/9666386 to your computer and use it in GitHub Desktop.
Simple example of normalized delta x and y values.
function love.load()
local start_x = 0
local start_y = 0
local end_x = 10
local end_y = 5
dx = (end_x - start_x)
dy = (end_y - start_y)
local distance = math.sqrt(dx^2 + dy^2)
x = start_x
y = start_y
dx = dx / distance
dy = dy / distance
end
function love.update(dt)
local speed = 100 * dt
x = x + dx * speed
y = y + dy * speed
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment