rotation check help
What i am trying to acomplish is that if the block is facing away from the block on the mouse pointer then it multiplies the cframe by 4. I already got a system for it, but it taks long finding the rotation and then putting that in the if statement, and it is not reliable at all.
code:
local mouseY = math.floor(mouseTarget.Orientation.Y)
local modelY = math.floor(Model.PrimaryPart.Orientation.Y)
local mouseX = math.floor(mouseTarget.Orientation.X)
local modelX = math.floor(Model.PrimaryPart.Orientation.X)
if modelX + mouseX == -1 then
modelX = 0
elseif modelX + mouseX == 89 then
modelX = 90
elseif modelY + mouseY < 180 then
modelY = 180
end
print(modelX.." "..mouseX)
print(modelY.." "..mouseY)
--------------------left and right--------------------
if mouseSurface==Enum.NormalId.Left then
if mouseY == modelY or mouseY+180 == modelY or mouseX-1 == modelX or mouseX == modelX or mouseX-180 == modelX or mouseY-180 == modelY or mouseX-90 == modelX or mouseX+90 == modelX or mouseX+89 == modelX then
we.C0 = CFrame.new(-(mouseTarget.Size.X+Model.PrimaryPart.Size.X)/2,0,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,Back)
elseif mouseY+90 == modelY or mouseY-90 == modelY then
we.C0 = CFrame.new(-(Model.PrimaryPart.Size.Z+mouseTarget.Size.X)/2,0,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))
end
elseif mouseSurface==Enum.NormalId.Right then
if mouseY == modelY or mouseY+180 == modelY or mouseX-1 == modelX or mouseX == modelX or mouseX-180 == modelX or mouseY-180 == modelY or mouseX-90 == modelX or mouseX+90 == modelX or mouseX+89 == modelX then
we.C0 = CFrame.new((mouseTarget.Size.X+Model.PrimaryPart.Size.X)/2,0,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,Back)
elseif mouseY+90 == modelY or mouseY-90 == modelY then
we.C0 = CFrame.new((Model.PrimaryPart.Size.Z+mouseTarget.Size.X)/2,0,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))
end
-------------------top and bottom---------------------
elseif mouseSurface==Enum.NormalId.Top then
mouseX = math.floor(mouseTarget.Orientation.Y)
modelX = math.floor(Model.PrimaryPart.Orientation.Y)
mouseY = math.floor(mouseTarget.Orientation.X)
modelY = math.floor(Model.PrimaryPart.Orientation.X)
if mouseX+90 ~= modelX and mouseY == modelY or mouseY-180 == modelY or mouseX == modelX or mouseX-1 == modelX or mouseX-180 == modelX or mouseX-90 == modelX or mouseX+90 == modelX or mouseX+89 == modelX then
we.C0 = CFrame.new(0,(Model.PrimaryPart.Size.Y+mouseTarget.Size.Y)/2,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,Back)
elseif mouseY+90 == modelY or mouseY-90 == modelY then
we.C0 = CFrame.new(0,(Model.PrimaryPart.Size.Z+mouseTarget.Size.Y)/2,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))
end
elseif mouseSurface==Enum.NormalId.Bottom then
mouseX = math.floor(mouseTarget.Orientation.Y)
modelX = math.floor(Model.PrimaryPart.Orientation.Y)
mouseY = math.floor(mouseTarget.Orientation.X)
modelY = math.floor(Model.PrimaryPart.Orientation.X)
if mouseX+90 ~= modelX and mouseY == modelY or mouseY-180 == modelY or mouseX == modelX or mouseX-1 == modelX or mouseX-180 == modelX or mouseX-90 == modelX or mouseX+90 == modelX or mouseX+89 == modelX then
we.C0 = CFrame.new(0,-(Model.PrimaryPart.Size.Y+mouseTarget.Size.Y)/2,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,Back)
elseif mouseY+90 == modelY or mouseY-90 == modelY then
we.C0 = CFrame.new(0,-(Model.PrimaryPart.Size.Z+mouseTarget.Size.Y)/2,0)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))
end
elseif mouseSurface==Enum.NormalId.Front then
if mouseY == modelY or mouseY+180 == modelY or mouseX-1 == modelX or mouseX == modelX or mouseX-180 == modelX or mouseY-180 == modelY or mouseX-90 == modelX or mouseX+90 == modelX or mouseX+89 == modelX then
if modelY >0 then
we.C0 = CFrame.new(0,0,-(Model.PrimaryPart.Size.X+mouseTarget.Size.Z)/2)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,2)
elseif modelY <0 then
we.C0 = CFrame.new(0,0,-(Model.PrimaryPart.Size.X+mouseTarget.Size.Z)/2)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,-2)
end
elseif mouseY+90 == modelY or mouseY-90 == modelY then
we.C0 = CFrame.new(0,0,-(mouseTarget.Size.X+Model.PrimaryPart.Size.Z)/2)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,Back)
end
elseif mouseSurface==Enum.NormalId.Back then
if mouseY == modelY or mouseY+180 == modelY or mouseX-1 == modelX or mouseX == modelX or mouseX-180 == modelX or mouseY-180 == modelY or mouseX-90 == modelX or mouseX+90 == modelX or mouseX+89 == modelX then
if modelY <0 then
we.C0 = CFrame.new(0,0,(Model.PrimaryPart.Size.X+mouseTarget.Size.Z)/2)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,2)
elseif modelY >0 then
we.C0 = CFrame.new(0,0,(Model.PrimaryPart.Size.X+mouseTarget.Size.Z)/2)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,-2)
end
elseif mouseY+90 == modelY or mouseY-90 == modelY then
we.C0 = CFrame.new(0,0,(mouseTarget.Size.X+Model.PrimaryPart.Size.Z)/2)*CFrame.Angles(math.rad(Diff),math.rad(Elev),math.rad(Rot))*CFrame.new(0,0,Back)
end
end
Basically, i want to find a way that is simpler then doing this.