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

Determine if part is overhanging?

Asked by 7 years ago

Hi folks! I've been racking my brain on this problem and can't figure a solution. Imagine a baseplate with a part on top. I'm trying to determine if the part is overhanging the base instead of being fully in contact.

A part's position doesn't change on rotation, but it can change from being fully in contact to overhanging if the part is a rectangular shape. Comparing the positions of the baseplate and part is definitely the right way to go, but I can't figure out to determine whether to use the X or Z size in my calculation since it changes on rotation.

Any help is greatly appreciated!

1 answer

Log in to vote
1
Answered by 7 years ago

Here's a simple solution. Will print validity of part as you move/rotate it.

local base = workspace.Base
local obj = workspace.Part
local pos
local ori;

while true do
    if(pos~=obj.Position)or(ori~=obj.Orientation)then
    pos=obj.Position
    ori=obj.Orientation
    local valid=false
    local baseX =math.abs(base.Position.X)+(base.Size.X/2)
    local baseZ =math.abs(base.Position.Z)+(base.Size.Z/2)
    local objX, objZ;
    if(math.abs(obj.Orientation.Y)==90)then
        --Xsize is Zdir
        objX =math.abs(obj.Position.X)+(obj.Size.Z/2)
        objZ =math.abs(obj.Position.Z)+(obj.Size.X/2)
    else
        objX =math.abs(obj.Position.X)+(obj.Size.X/2)
        objZ =math.abs(obj.Position.Z)+(obj.Size.Z/2)
    end
    if(baseX>=objX)and(baseZ>=objZ)then
        print(true)
    else
        print(false)
    end;end
    wait()
end
Ad

Answer this question