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
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.
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.
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.