Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a non-colliding part detect if a colliding part is inside it?

I've tried GetTouchingParts, but that doesn't work since it only works with colliding parts. I've also tried Touched, but again, same problem. How do I tackle this problem? Edit: Sorry, I mean if the non-colliding part is inside it!

2 comments

0

Con-Colliding parts can still use the touched event.

0

Updated, sorry!

1 answer

Math ;D I'm pretty happy with this.

local part1size = workspace.part1.Size
local part1position = workspace.part1.Position
local part2size = workspace.part1.Size
local part2position = workspace.part2.Position

function checkX()
	local x1, x2 = part1size.X, part2size.X
	local x = x1 + x2
	
	return(part1position.X + x > part2position.X or  part1position.X - x < part2position.X)
end

function checkY()
	local y1, y2 = part1size.Y, part2size.Y
	local y = y1 + y2
	
	return(part1position.Y + y > part2position.Y or  part1position.Y - y < part2position.Y)
end

function checkZ()
	local z1, z2 = part1size.Z, part2size.Z
	local z = z1 + z2
	
	return(part1position.Z + z > part2position.Z  or  part1position.Z - z < part2position.Z)
end



if checkX() and checkY() and checkZ() then
	print"WOOOOOO COLLIDING"
end

This discussion is preserved as it was. New answers, comments, and votes are closed.