CFrame rotating around the wrong axis

Hello!

I’m currently trying to rotate a part using an orientation CFrame returned by a sensor on the user device but I keep running into a problem.

Here is a representation of what I want to do :


At the start, when I rotate my device up and down you can see that the part rotates around the green line. Hovewer, when I rotate my device 90 degrees around the blue line and then rotate it up and down, the part will rotate around the red line instead of the green one.

Would there be a way to apply the given rotation in a way where it would do what I described above?

I did manage to find something that works but it is very hard to modify anything about the CFrame whitout it breaking so I’m trying to find an alternative.

Thanks !

We don’t know what your code looks like, so we can’t assist you.

We need to know what your CFrame calculations are to find the problem, unless someone else has encountered a similar issue.

1 Like

Have you messed around with the CFrame order of operations?

That usually does the trick from my experience. The axis of rotation heavily depend on the CFrame order of operations.

But otherwise no code and it’s pretty difficult as @IDoLua said.

This is the current code that I’m using.

local Input, RotCFrame = UserInputService:GetDeviceRotation()
local X, Y, Z = RotCFrame:ToOrientation()
		
Part.CFrame = CFrame.new(Part.Position) * CFrame.fromOrientation(X, Y, Z)

And this is the first one which works but why makes it hard to edit the CFrame. Thing is, I’m not even sure if it is actually caused by the code.

local Input, RotCFrame = UserInputService:GetDeviceRotation()
local X, Y, Z = RotCFrame:ToOrientation()
		
Part.CFrame = CFrame.new(Part.Position) * CFrame.fromEulerAnglesYXZ(X, Z, Y)

It’s nothing to do with the code per se, I mean, it is; the angle conversion method you use (be it Euler/Orientation,) is important.

This is probably because you’re getting a gyroscopic output of the orientation from the device; meaning if it goes up and down, it’s still pitching up and down no matter which way it faces, and it affects the same “origin” plane.

Okay I’m going to stop now before I make a fool of myself. I’m too exhausted, you can take it from here @dthecoolest and see if you can help our friend out.

Just to be sure I’m not doing this for nothing, I would like to check if the fact that editing the CFrame while using the old code is so hard was due to the old code or just me doing thing the wrong way.

My problem was that everytime I wanted to apply an offset to the rotation and have it do the same effect as in the video(the axis getting rotated) I would need to every time find a new formula as doing it the way it worked the line before would create weird behaviour.

Here is a concrete example :

local X, Y, Z = Rotation:ToOrientation()
local UserX, UserY, UserZ = (CFrame.fromEulerAnglesYXZ(X, Z, Y) * CFrame.Angles(math.rad(135), 0, 0)):ToEulerAnglesYXZ()
RightShoulder.C0 = CFrame.new(RightShoulder.C0.Position) * (CFrame.fromEulerAnglesYXZ(X, Z, Y) * CFrame.Angles(math.rad(-45), 0, 0))

This is supposed to apply an offset to the Y axis of I think 90 degrees. It worked but changing any values (if for example I now wanted an offset of 45) would lead to I breaking and needing to make another formula. Tough, if you would look at the start of the full code this time for the camera CFrame, simply adding my offset to the Y axis would do the trick.

So maybe the old code works but the way I’m applying the offset is wrong.

how the hell do we fix this sir please help