Skip to content

Instantly share code, notes, and snippets.

@Warr1024
Created September 19, 2019 20:16
Show Gist options
  • Save Warr1024/fce81198bcae5256f7665c73611f9256 to your computer and use it in GitHub Desktop.
Save Warr1024/fce81198bcae5256f7665c73611f9256 to your computer and use it in GitHub Desktop.
Horizontal Spread Raycasting
local spread = math.pi / 16
local amount = 13
local range = 4
local function doraytrace(start, target)
for pointed in minetest.raycast(start, target, false, false) do
local pos = pointed.intersection_point
minetest.add_particle({
pos = pos,
exptime = 1,
texture = "fake",
size = 1,
glow = 15
})
end
end
local function swing(player)
local camera_z = player:get_look_dir()
local camera_x = minetest.yaw_to_dir(player:get_look_yaw())
local start = player:get_pos()
start.y = start.y + 1.62
for i = -amount / 2, amount / 2 do
local rel = vector.multiply(minetest.yaw_to_dir(spread * i), range)
local target = vector.add(start, vector.multiply(camera_z, rel.z))
target = vector.add(target, vector.multiply(camera_x, rel.x))
doraytrace(start, target)
end
end
minetest.register_tool(minetest.get_current_modname() .. ":x", {
on_use = function(stack, who)
swing(who)
return stack
end
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment