Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function get_ray(range)
- local p = minetest.camera:get_pos()
- p.x = p.x / 10
- p.y = p.y / 10
- p.z = p.z / 10
- local direction = minetest.camera:get_look_dir()
- local limit = vector.multiply(direction, range)
- local finish = vector.add(p, limit)
- local ray = minetest.raycast(p,
- finish,
- false, -- include objects
- true) -- include liquids
- return ray
- end
- local function is_good_hit(thing)
- if thing == nil then return false end
- if thing == "default:air" then return false end
- return true
- end
- function Pointer(range)
- range = range or 4 -- let's hope for the best -_-
- local item = ""
- local node_pos = nil
- for hit in get_ray(range) do
- local thing = minetest.get_node_or_nil(hit.under) -- to get some coords
- if thing ~= nil then
- thing = thing.name
- end
- if is_good_hit(thing) then
- item = thing
- node_pos = hit.under
- break
- end
- end
- return item, node_pos
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement