I’m working on a dungeon project in Roblox and encountering a challenge with positioning a piece accurately against the walls of my dungeon. I’m aiming to create a “green zone” that should snap perfectly to the walls of a model, but I’m running into issues where the green zone either overlaps with the model or doesn’t align as expected.
Here’s a summary of the problem:
Objective: I need to position a green zone (a part) so that it snaps perfectly to the walls of a model. The green zone should be aligned with the surface of the walls and fit seamlessly into the model.
Current Approach:
I’m using a bounding box to calculate the dimensions and position of the model.
I cast rays in different directions to detect the closest wall and its surface normal.
Based on the detected wall, I attempt to move the green zone to align with that surface.
Issues Encountered:
The green zone sometimes overlaps with the model or does not align correctly with the wall.
The green zone can end up in an incorrect position, even though it’s supposed to snap precisely to the surface of the wall.
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:
Phantom collisions: The engine detects collisions with the union part, even though it visually appears that there is no intersection.
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:
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.
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
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 !!!