Need Help with Snapping a Piece to a Wall in My Roblox Dungeon

Edit your code to add to the position where it would snap

What do you mean so after my analysis I noticed that the problem is because of the union piece at the bottom that is here


Here’s the thing ChatGPT explained to me which makes it sense

Union parts in Roblox are a combination of multiple parts, and sometimes the collision boundaries (the so-called “hitboxes”) of these unions are slightly offset or less accurate than regular parts. This can result in the following behaviors:

  1. Phantom collisions: The engine detects collisions with the union part, even though it visually appears that there is no intersection.
  2. Inconsistent hitboxes: The union part might have a slightly larger or smaller hitbox than expected, leading to undesired collision detections.

Then after he said

Set CollisionFidelity on Union: Each union part has a CollisionFidelity property, which determines how accurately collisions are calculated. The default value may not be sufficient for precise interactions, so try setting it to a more accurate mode, such as:

unionPart.CollisionFidelity = Enum.CollisionFidelity.PreciseConvexDecomposition

which unfortunately didn’t work since it throw the error

The current thread cannot write ‘CollisionFidelity’ (lacking capability Plugin)

So I tried this :
Capture d’écran 2024-09-05 214607

Didn’t work either

You could use shapecast, instead of raycast. Shapecast the green zone on the X axis to the left and to the right, see which side has a result (if both have a result, take shortest), and move the zone by using the resulting vector. Then do the z axis.

How do you use that interesting never heard of this concept ?

You take the object, a vector and RaycastParams. It’ll raycast the whole object.

Is it accurate touching detection because union parts seems to have an issue with the bounding box unlike part ?

Should be. Also, you can set our CollisionFidelity to ConvexHull for a more accurate collider.

I already tried this sadly didn’t work but I’ll try the shapecast

1 Like

I mean, if the collider is wrong, shapecast probably won’t work either. I assume rays intersect with the collider, not the geometry.

Ok but why there’s a problem when the zone is near union and not touching it at all but it’s not a problem where the touching object is a part then ?

Oh alright thanks man I’ll check a tutorial on rays

I found the issue in my code it’s this line

local minBound = Vector3.new(math.huge, math.huge, math.huge)
	local maxBound = Vector3.new(-math.huge, -math.huge, -math.huge)

	for _, part in ipairs(model:GetDescendants()) do
		if part:IsA("BasePart") then
			local partMin = part.Position - part.Size / math.huge
			local partMax = part.Position + part.Size / math.huge

			minBound = Vector3.new(
				math.min(minBound.X, partMin.X),
				math.min(minBound.Y, partMin.Y),
				math.min(minBound.Z, partMin.Z)
			)
			maxBound = Vector3.new(
				math.max(maxBound.X, partMax.X),
				math.max(maxBound.Y, partMax.Y),
				math.max(maxBound.Z, partMax.Z)
			)
		end
	end

	-- Expand the bounds slightly to ensure the outline is outside the piece
	local expansionOffset = Vector3.new(0.75, 0.5, 0.75)  -- Adjust this value as needed
	minBound = minBound - expansionOffset
	maxBound = maxBound + expansionOffset

	local size = maxBound - minBound
	local center = (minBound + maxBound) / 2

How can I know if ray of union intersect with the Green Zone ??

This is a difficult problem that I’m not sure you have the skills to solve, and for me it would take quite a while to solve. There’s easier ways to do what you want to do… You could work with a grid, where every part is always 1x1 cell size. That way you can just say a cell is full or empty.

I’m not sure if I fully understand your request, but it seems like you want to position an object perfectly aligned with the wall. Would it not be sufficient to place a target object, which is invisible and non-collidable, in that exact position, and then move the green zone to match the position of your target object when needed?

Sorry I came back hum basically I want to make a zone in which it will be useful for the compatiblity piece of my dungeon and the green zone would base off of a region however problem is when I put a green box it destroys because it detects that by the method it’s in a part but from my human visual perspective it’s a green zone placement perfectly valid

Shit I think the corners of the piece will help me solves my union collision problem man although I’m not 100 % sure this is a proof solution but I will definitely give it a try !!!


It didn’t include the union part in the corners man

Seems very legit now let’s try to implement it overall I used this thread to help me

how to find corners in a part

Sadly :disappointed_relieved: doesn’t work unfortunately