# Part Rotation Along Local Axis

Is there a way to determine how much a part is rotated about one of it’s local axes? For example, let’s say I would like to know how much a part is rotated about its local Z axis.

2 Likes

I am guessing that you would need to have a record of each step of the rotation so you can determine the amount.

I am not sure if mathematically it is even possible to determine the rotation along a local axis from a given a CFrame. But I thought I would ask, just in case.

I would start by figuring out the axis angle representation which should help

At least, if I was trying to figure out this problem, that’s where I’d start.

2 Likes

What exactly do you mean by local axes? Are you asking for a way to determine how much an object is rotated relative to itself?

Sorry @Vathriel I didn’t mean to reply to you here.

1 Like

An analogy would be how you can apply transformations in Studio in either world space, or in object space (hit control L). In object space, also called local space, the transformations are relative to the axes of the part, rather than the world axes.

I could be wrong but I believe the answer is always going to be angles of 0 degrees. An object’s world space orientation is expressed by it’s Orientation field. Since this is relative to world space we would want to convert it to our object’s space. In which case the relative angles would be the same, thus cancelling eachother out.

Here’s an example of this. I’ve created my own axis handles here. The first image shows these handles at the Object’s CFrame as an example of the part’s world space translation

This one is an example a local space translation, where the axis handles are going to be at angle (0, 0, 0) since the angles cancel eachother out.

This isn’t necessarily a proof of this but I think it shows that a parts angle along it’s “local axis” is always 0, 0, 0.

I apologize if I’ve misunderstood your question. I’ve answered it as I’ve understood it.

1 Like

Coordinates must be relative to something. In World Space, the coordinate system is relative to base {(1,0,0), (0,1,0), (0,0,1)}. To calculate the coordinates of your Part in an alternative coordinate system (whatever you choose your ‘Local Axis’ reference to be), you need to use an appropriate transformation basis matrix and perform a Change of Base.

Yes there is a way to do this. You will need two CFrame values to calculate this though, its impossible to do with just one CFrame, you would just get zero for all the angles. The two CFrame values you need I will call the Reference CFrame and the Rotated CFrame. The reference cframe is like the origin. The rotated cframe is the cframe that started at the origin but has been rotated. Using some cframe commands we can calculate which local axis it was rotating on and by how many degrees it was rotated on each local axis.

here is some code that does what I just described

``````local referenceCFrame = --CFrame of part BEFORE it was rotated
local rotatedCFrame = --CFrame of part AFTER it was rotated, which should also be its current cframe

--Bring the rotatedCFrame into the local space
local localCFrame = referenceCFrame:ToObjectSpace(rotatedCFrame)

--Now get many radians on each local axis the part has rotated from "referenceCFrame" to reach "rotatedCFrame"
local angleX, angleY, angleZ = localCFrame:ToEulerAnglesXYZ()

angleX = math.deg(angleX)
angleY = math.deg(angleY)
angleZ = math.deg(angleZ)
``````

Thats all there is to it, I hope this made sense and that it helped you out, if anything I said needs clarification just ask and ill do my best to explain it.

12 Likes

Hello, in a very similar vein how would you rotate the part about a local axis?

Its quite simple.

`Part.CFrame = Part.CFrame *CFrame.Angles(angleX, angleY, angleZ)`

When you multiply CFrame.Angles() by a part’s current cframe then the rotation will be about its local axis. In the line of code above angleX, angleY and angleZ will all be rotated about the part’s current local axis

1 Like

Mhh that isnt working that good at me can pls someone help me.

robloxapp-20220406-0030366.wmv (739.8 KB)

Used code in command bar:

``````while game.Workspace:FindFirstChild("DeleteToStop") ~= nil do local x, y, z = (CFrame.new():ToObjectSpace(game.Workspace.VectorB.CFrame)):ToEulerAnglesXYZ()   workspace.VectorA.CFrame = CFrame.new(game.Workspace.VectorA.CFrame.Position) * CFrame.Angles(0,y,0) wait() end
``````

Side note: Upss I meant to post this on ur post above.

Nvm I already got a solution. I used :ToOrientation() insted of eulerangles