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

Test if part is under a different part local(y)?

Asked by 3 years ago
Edited 3 years ago

So I know you can do like

local part = workspace:FindFirstChild("ooga")
if script.Parent.Position.Y  >= part.Position.Y then
    -- Do whatever
end

but what if the part was tilted on the Z axis 90 degrees, how would you be able to tell if the part is above or below it? (Local to the part)

0
using the same logic lmao. What do you mean local to the part? If you want to know if a part is on top / below, rely on the y axis like you demonstrated greatneil80 2647 — 3y
0
What I want to do is like "if part.position <= script.parent.CFrame.y then" GameStealerKid 79 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

To find where a part is positioned relative to another part you can use their CFrames to find an offset. This offset is the relative position and rotation between those two objects, so if you were to translate A by the offset between A and B, you'd get B. It's a bit hard to understand at first but once you start using it more it starts making more sense.

The CFrame object already has a function to find this offset; ToObjectSpace().

Here's an example of how it can be used, and how it can solve your problem.

local c0 = workspace.Part0.CFrame
local c1 = workspace.Part1.CFrame

local offset = c0:ToObjectSpace(c1)
print(offset.Position.Y) -- This will print the relative Y coordinate between the parts, which can be used to find whether or not a part is below or above another part.
0
It's either a really good answer I don't understand at all or you don't get what I mean. GameStealerKid 79 — 3y
Ad

Answer this question