Created
March 20, 2014 15:28
-
-
Save Uradamus/9666386 to your computer and use it in GitHub Desktop.
Simple example of normalized delta x and y values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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