Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rad_to_deg(angle) return angle/math.pi*180 end
- function calculate_angles(x, y, z, ex, ey, ez)
- local pos =
- {
- ['x']=x,
- ['y']=y,
- ['z']=z
- }
- local enemy_pos =
- {
- ['x']=ex,
- ['y']=ey,
- ['z']=ez
- }
- local displacement =
- {
- ['x']=pos['x']-enemy_pos['x'],
- ['y']=pos['y']-enemy_pos['y'],
- ['z']=pos['z']-enemy_pos['z']
- }
- local unsigned_aim_angles =
- {
- ['horizontal']=rad_to_deg(math.abs(math.atan(displacement['x']/displacement['z']))),
- ['vertical']=rad_to_deg(math.abs(math.atan(displacement['y']/math.sqrt(math.pow(displacement['x'], 2)+math.pow(displacement['z'], 2)))))
- }
- local aim_angles =
- {
- ['horizontal']=0,
- ['vertical']=0
- }
- if displacement['x'] < 0 then
- aim_angles['horizontal'] = -unsigned_aim_angles['horizontal']
- print('-x')
- if displacement['z'] > 0 then
- aim_angles['horizontal'] = -180 - aim_angles['horizontal']
- end
- else
- aim_angles['horizontal'] = unsigned_aim_angles['horizontal']
- print('+x')
- if displacement['z'] > 0 then
- aim_angles['horizontal'] = 180 - aim_angles['horizontal']
- end
- end
- if displacement['y'] < 0 then
- aim_angles['vertical'] = unsigned_aim_angles['vertical']
- else
- aim_angles['vertical'] = -unsigned_aim_angles['vertical']
- end
- return aim_angles
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement