osmarks

LAZOR API

Jan 2nd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.65 KB | None | 0 0
  1. local laser_speed = 1.5
  2.  
  3. return function(fire, power)
  4.     return function(entity)
  5.         local m = vector.new(entity.motionX, entity.motionY, entity.motionZ)
  6.         local p = vector.new(entity.x, entity.y, entity.z)
  7.         local t = p:length() / laser_speed -- time for laser to reach target
  8.         local o = m * t -- offset from original position when laser would have reached target
  9.         local n = p + o -- final position of entity at point when laser would have reached target (good enough?)
  10.         local x, y, z = n.x, n.y, n.z
  11.  
  12.         local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
  13.         local yaw = math.atan2(-x, z)
  14.  
  15.         fire(math.deg(yaw), math.deg(pitch), power)
  16.     end
  17. end
Add Comment
Please, Sign In to add comment