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

Getting the sides of a part no matter the rotation?

Asked by 9 years ago

Let's say I have a part and I want to duplicate this part and put the clone next to, on top of, or under the part.

But, if the part is rotated, the BottomSurface could actually be facing the top, and vice versa.

I got it working for front and back, since I can just use lookVector for that.

local mouse = game.Players.LocalPlayer:GetMouse(); 

local inverted = -1; 

mouse.KeyDown:connect(function(key) 
    if (key=="x") then 
    if (mouse.Target) then 
        local surface = mouse.TargetSurface; 
        if (surface==Enum.NormalId.Front) or (surface==Enum.NormalId.Back) then 
            if (surface==Enum.NormalId.Back) then inverted=-1 else inverted=1 end; 
            local p = mouse.Target:clone(); 
            p.CFrame = mouse.Target.CFrame + ((mouse.Target.CFrame.lookVector*mouse.Target.Size.Z)*inverted); 
            p.Parent=workspace; 
end end end end); 

The above code works correctly for placing a block on the front or back, and works no matter what the rotation of the block is.

How would I do that same thing for the other sides, since I can't use lookVector?

( This is inside of a local script. )

Answer this question