Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago
Edited 7 years ago

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!

0
Con-Colliding parts can still use the touched event. User#11440 120 — 7y
0
Updated, sorry! coolyoshipower 42 — 7y

1 answer

Log in to vote
0
Answered by
Notwal 2
7 years ago

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

Ad

Answer this question