Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Relative Angles
local cast_hits = { { point = {x=2,y=0,z=2}, normal = {x=1,0,0}, distance = 4, hit_object = { guid = "001" }, }, { point = {x=-2,y=0,z=2}, normal = {x=1,0,0}, distance = 4, hit_object = { guid = "002" }, }, { point = {x=-1,y=0,z=-4}, normal = {x=1,0,0}, distance = 4, hit_object = { guid = "003" }, }, } local cast_results = {} local range = 10 local fov = 120 local heading = 315 local mypos = { x = 0, y = 0, z = 0 } local myrot = { x = 0, y = 0, z = 0, } --auto worky local h_fov = fov/2 local max_angle = myrot.y + heading + h_fov local min_angle = myrot.y + heading - h_fov print("Checking for targets within "..h_fov.." of "..heading) print("Min angle "..min_angle) print("Max angle "..max_angle) -- add results to table for k,v in pairs(cast_hits) do if v or v ~= '' then --check within range if v.distance <= range then local target_heading = math.deg(math.atan2(v.point.x - mypos.x, v.point.z - mypos.z)) --target_heading = target_heading + 360 print("Found target "..v.hit_object.guid.." at "..target_heading) if target_heading <= max_angle and target_heading >= min_angle then table.insert(cast_results, {v.hit_object.guid, target_heading, v.distance}) end end end end print("Printing refined results: ") for k,v in pairs(cast_results) do print("Found object: "..v[1].." at "..v[2]..", "..v[3]) end
run
|
edit
|
history
|
help
0
personal use
help with lua number input
Surface Area of things (Incomplete)
Area of Sector Calculator
Eliminatoria minigame
test
lua5.3: ...Desktop/rextester_linux_2.0/usercode/68368288/source.lua:166: unexpected symbol near '}'
10 Line challenge
Fixed
Enums in Lua (library)