Hello! I’m having issues correctly applying device rotation to a part. This is caused by the fact that the returned rotation is not relative to the “real life axis”.
Here is an example which is clearer than the above because I don’t posses the direct knowledge of the terms to explain it.
Let say your device rotation is (0, 0, 0) and you turn the device 45 degrees on the X, your rotation will be (45, 0, 0). Now, if you go back and firstly turn your device by 90 degrees on the Y and then try to turn the device on the X axis relative to real life, it will give you (0, 90, 45).
The because is that when you rotate the device, the Z axis became visually the “X” but the device doesn’t take that in concider that so it just sticks with the default axis.
Here is the snippet of code I’m using to test and debug.
local UserInputService = game:GetService("UserInputService")
local Board = Instance.new("BillboardGui")
local Label = Instance.new("TextLabel")
local Visualizer = Instance.new("Part")
Visualizer.Position = Vector3.new(-11, 4.5, 0)
Visualizer.Parent = workspace
Visualizer.Anchored = true
Board.Parent = Visualizer
Label.Parent = Board
UserInputService.DeviceRotationChanged:Connect(function(Input, Rotation)
local X, Y, Z = Rotation:ToEulerAnglesXYZ()
Visualizer.Rotation = Vector3.new(math.deg(X), math.deg(Y), math.deg(Z))
Label.Text = tostring(math.deg(X)).." "..tostring(math.deg(Y)).." "..tostring(math.deg(Z))
end)
There should be some fairly common operation that would rotate the euler to make it relative. I’m trying to save myself probably a lot of time by asking here so thanks for helping!