How to know which way a part decal is facing

So I made a slot machine, as of now its not random, but when you spin it it will not land exactly on an image/decal (there is one per side of cylinder) How would I know what decal it landed closet to so I can know where to rotate them and also what they actually landed on.

My only guess is that you check the orientation, and then use stuff like <= and =>, not tested so I don’t actually know if it will work .

Then use if the orientation is in the range of one of the decals orientation, change the orientation to the decals when facing the right way.

1 Like

You can either set bounds for the orientation, or, you can use a little math.

If you want to use the bounds method, you basically create a bunch of if statements to check if the orientation of the cylinder falls within a range:

local orientation = --> a number that tells you the orientation of the rotating axis

if orientation >= 0 and orientation < 90 then
  --> slot 1
elseif orientation >= 90 and orientation < 180 then
  --> slot 2
elseif orientation >= 180 and orientation < 270 then
  --> slot 3
elseif orientation >= 270 and orientation < 360 then
  --> slot 4
end

If you want to use a mathematical method, you can compare the surface normals to see which normal matches the target line:

local normals = { --> set these values to the direction of each decal
    Slot1 = CFrame.UpVector,
    Slot2 = CFrame.LookVector,
    Slot3 = -CFrame.UpVector,
    Slot4 = -CFrame.LookVector,
}

local targetDirection = SlotMachine.TargetFace --[[
    not a real property, but this is the direction that tells you which
    slot was selected
]]

local closestDot = -1
local closestSlot
for slot, normal in normals do
    local dot = targetDirection:Dot(normal) --> dot product compares how much 2 vectors are facing each other
    if dot < closest then 
        closest = dot
        closestSlot = slot
    end
end

print(closestSlot)
1 Like

The first one seems best for me, but orientation only has 0-90 and -0–90 so that wouldnt work, at least i think so.

EDIT:

Decided to use the 2nd option, but I have no idea what you mean by TargetFace.

Sorry I couldn’t help much, I’m being honest I’m not familiar with orientation at all, not very surprised it didn’t work.