How to find which face is up?

So basically, i’m trying to make something that recognizes which face of a part is up, (for example) if you rolled a cube, then for example it lands on the back face, therefor the front face would be up

however, i cant seem to get that working, and i havent found any solution online

all im asking for is if theres a way, what function do i call, or what do i use for that

1 Like

I don’t know if this method is effective. But, you can use the part’s orientation. There probably is a better way of doing this but this is the only method I am aware of. There might be a way of using CFrames as well but, if there is I don’t know of it. These articles could help. Positioning Objects. Basepart.Orientation.

1 Like

You could use the lookVector, upVector, or rightVector property of the part’s CFrame by looking at the Y axis associated with each one.
Each one of these properties are unit vectors associated with the part’s sides.
For example, imagine the part lands with the up surface facing up, its upVector’s Y axis would be 1, while both the rightVector and lookVector would be 0

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 cs.side
end

--findSide will return the part's side which is facing up, as a string

So I went through lookVector, upVector, and rightVector, as well as their opposite(which represented the other side of the part) and check if the Y property of that unit was greater than the current side’s which is saved in a table, cs.

12 Likes

this worked for everything but the bottom surface, the cubes rotation is 0,0,90 , its up-facing part is RightSurface

1 Like

Here I am staring at it for 30 minutes wondering what I did wrong only to find out after the if statements, I was only setting cs.y to lookvector’s Y xd.
edited it.

alright, works like a charm, ROBLOX really needs to add a function for you to check for that stuff, lol

2 Likes