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

How to detect which side of a cube is up?

Asked by 3 years ago

ive already tried a code from devforum, but it doesnt work, so how do i detect what side of a cube is up?

the code btw:

function findSide(part)
     local cf=part.CFrame
     local cs={side=nil,y=-2}
     if cf.lookVector.Y>cs.y then cs.side="FrontSurface" cs.y=cf.lookVector.Y end
     if -cf.lookVector.Y>cs.y then cs.side="BackSurface" cs.y=-cf.lookVector.Y end
     if cf.rightVector.Y>cs.y then cs.side="RightSurface" cs.y=cf.rightVector.Y end
     if -cf.rightVector.Y>cs.y then cs.side="LeftSurface" cs.y=-cf.rightVector.Y end
     if cf.upVector.Y>cs.y then cs.side="TopSurface" cs.y=cf.upVector.Y end
     if -cf.upVector.Y>cs.y then cs.side="BottomSurface" cs.y=-cf.upVector.Y end
     return script.Parent.numdisplay.TextLabel.Text
end

Im trying to change a textlabels text to the side that the cube is on, but nothing is changing.

1 answer

Log in to vote
1
Answered by
Cirillix 110
3 years ago
Edited 3 years ago
function findSide(part)
     local cf=part.CFrame
     local cs={side=nil,y=-2}
     if cf.lookVector.Y>cs.y then cs.side="1" cs.y=cf.lookVector.Y end --FrontSurface
     if -cf.lookVector.Y>cs.y then cs.side="2" cs.y=-cf.lookVector.Y end --BackSurface
     if cf.rightVector.Y>cs.y then cs.side="3" cs.y=cf.rightVector.Y end --RightSurface
     if -cf.rightVector.Y>cs.y then cs.side="4" cs.y=-cf.rightVector.Y end --LeftSurface
     if cf.upVector.Y>cs.y then cs.side="5" cs.y=cf.upVector.Y end --TopSurface
     if -cf.upVector.Y>cs.y then cs.side="6" cs.y=-cf.upVector.Y end --BottomSurface
     return cs.side --Return the function as the side number
end

while wait() do
script.Parent.numdisplay.TextLabel.Text = findSide(script.Parent) --Since you returned cs.side, "findSide" is now a string and you can use it for the text label
end

This should work. It wasn't working because you were returning the text of the textlabel and not doing anything about it.

0
ok cool, is there a way to make it change if the side of the cube changes? also, is there a way to number the surfaces and display the number? Jakob_Cashy 79 — 3y
0
Make it change what exactly ? And yes there is a way to number the surfaces. Cirillix 110 — 3y
0
so if i move the cube and then the right surface is up, it should say rightsurface Jakob_Cashy 79 — 3y
Ad

Answer this question