I’m trying to get the necessary degrees on the Y axis of a model, based on the models UpVector.
I have these 3 models. All 3 have different direction. Ball shows top surface of the model.
I wanna be able to rotate both models on the green axis
When I rotate this model on the green axis
it’s Y value changes, easy.
However this one
has the X value change. So I need a way to get based on a models LookVector which axis to look and get its rotation from it
while true do
task.wait(0.1)
local Model = workspace.Folder:FindFirstChildWhichIsA("Model")
if not Model then
continue
end
-- Attempt 1
--local LookVector = Model:GetPivot().LookVector
--local rotationRadians = math.atan2(-LookVector.Z, LookVector.X)
--local rotationDegrees = math.deg(rotationRadians)
---- Get the rotation value based on the RotationIndex
--local RotateAmount = true and 15 or 1
---- Calculate the nearest multiple of RotateAmount for the current rotation
--local nearestMultiple = math.floor((rotationDegrees + 0.5 * RotateAmount) / RotateAmount) * RotateAmount
---- Set self.Rotation to the nearest multiple
--Rotation = nearestMultiple
--print(Rotation)
-- Attempt 2
--local x,y,z = Model:GetPivot():ToOrientation()
--print(math.floor(math.deg(y)))
-- Attempt 3
--local x,y,z = Model:GetPivot():ToEulerAnglesXYZ()
--print(math.floor(math.deg(y)))
-- Attempt 4
--local x,y,z = Model:GetPivot():ToEulerAngles()
--print(math.floor(math.deg(y)))
-- Attempt 5
local _, Rotation = Model:GetPivot():ToAxisAngle()
print(math.deg(Rotation))
-- Rotate on set pivot
Model:PivotTo(Model:GetPivot() * CFrame.Angles(0, math.rad(5), 0))
end
I have this code where I try 5 different methods, all don’t result in what I want. They’ll work for the model thats facing up, but not sideways