Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix short raycasts missing large objects #14339

Merged
merged 2 commits into from Feb 4, 2024

Conversation

appgurueu
Copy link
Contributor

Increases the tolerance from one node to five nodes. Also optimizes the "sphere" used for pre-filtering entities to start in the middle of the line segment rather than at the start.

Fixes #14337

How to test

See the issue. Note: The mod depends on futil and fmod (mods by flux, available on CDB). Alternatively, you can modify it to use particles (which I find slightly nicer), and also use that to look at the raycasts:

diff --git a/init.lua b/init.lua
index 53177e5..a71925f 100644
--- a/init.lua
+++ b/init.lua
@@ -30,15 +30,26 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
 	player:set_wielded_item(wielded_item)
 end)
 
+local function add_marker(pos, color)
+	minetest.add_particle({
+		pos = pos,
+		texture = "short_raycast_waypoint.png^[multiply:" .. color,
+		expirationtime = 60,
+		size = 1,
+	})
+end
+
 local function multicast(start, stop, objects, liquids, step)
 	local pos = start
 	local delta = (stop - start):normalize() * step
+	add_marker(pos, "red")
 	local function get_next_ray()
 		local old_pos = pos
 		pos = pos + delta
 		if start:distance(pos) > start:distance(stop) then
 			return
 		end
+		add_marker(pos, "red")
 		return Raycast(old_pos, pos, objects, liquids)
 	end
 	local ray = get_next_ray()
@@ -72,13 +83,7 @@ minetest.register_tool("short_raycast:caster", {
 
 		for pt in multicast(start, start + (100 * look), true, false, step) do
 			if pt.type ~= "object" or pt.ref ~= user then
-				futil.create_ephemeral_hud(user, 60, {
-					hud_elem_type = "image_waypoint",
-					text = "short_raycast_waypoint.png",
-					scale = { x = -1 / 16 * 9, y = -1 },
-					alignment = { x = 0, y = -1 },
-					world_pos = pt.intersection_point,
-				})
+				add_marker(pt.intersection_point, "white")
 				break
 			end
 		end

It should look something like this:

Screenshot from 2024-02-02 22-55-24

Increases the tolerance from one node to five nodes.
Also optimizes the "sphere" used for pre-filtering entities
to start in the middle of the line segment rather than at the start.
@appgurueu appgurueu added Bugfix 🐛 PRs that fix a bug Trivial The change is a trivial bug fix, documentation or maintenance change, as per the Git Guidelines labels Feb 2, 2024
@fluxionary
Copy link
Contributor

The mod depends on futil and fmod

oh whoops, i copied that code without noticing the dependency. i'll replace it with your particles.

Copy link
Member

@grorp grorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, haven't tested

@appgurueu appgurueu merged commit 1d9c971 into minetest:master Feb 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix 🐛 PRs that fix a bug One approval ✅ ◻️ Trivial The change is a trivial bug fix, documentation or maintenance change, as per the Git Guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

short raycasts don't see objects when passing through the tops of tall ones
3 participants