Skip to content

Instantly share code, notes, and snippets.

@codetravis
Created March 9, 2015 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codetravis/69c9b5c91bcb4cae3972 to your computer and use it in GitHub Desktop.
Save codetravis/69c9b5c91bcb4cae3972 to your computer and use it in GitHub Desktop.
Basic 2D Velocity Calculation
Local deltax:Float = Abs(target.x - position.x)
Local deltay:Float = Abs(target.y - position.y)
Local sum_delta:Float = deltax + deltay
If (target.x > position.x)
velocity.x = speed * (deltax / sum_delta)
Else If (target.x < position.x)
velocity.x = -speed * (deltax / sum_delta)
End
If (target.y > position.y)
velocity.y = speed * (deltay / sum_delta)
Else If (target.y < position.y)
velocity.y = -speed * (deltay / sum_delta)
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment