Skip to content

Instantly share code, notes, and snippets.

@error454
Created July 30, 2014 09:56
Show Gist options
  • Save error454/478fe33f77533347bc84 to your computer and use it in GitHub Desktop.
Save error454/478fe33f77533347bc84 to your computer and use it in GitHub Desktop.
Basic Vectors
local ex,ey,ez = object.getTranslation ( hEnemy,object.kGlobalSpace )
local ox,oy,oz = object.getTranslation ( o,object.kGlobalSpace )
-- vector pointing at the enemy
local dx,dy,dz = math.vectorSubtract ( ex,ey,ez,ox,oy,oz )
-- distance between enemy and object
local dist = math.vectorLength ( dx,dy,dz )
-- vector pointing at enemy with length of half the distance
local fx,fy,fz = math.vectorSetLength ( dx,dy,dz, dist * 0.5 )
-- Coordinate starting at the character going dist * 0.5 towards enemy
local x,y,z = math.vectorAdd ( ox,oy,oz,fx,fy,fz )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment