Why does CFrame turn the orientation to 0 too?

So I Want to set a models position to 0,0,0 so I used setPrimaryPartCFrame and set it to 0 just a normal modelTarget:SetPrimaryPartCFrame(CFrame.new(0, 0, 0)) but for some reason it also sets the orientation to 0,0,0 too why??

1 Like

Because cframes are a matrix of position and rotation. CFrame.new(0,0,0) is just equivalent to position (0, 0, 0), orientation 0.

1 Like

That shouldn’t be true though because I would have to specify CFrame.Angles() to access the rotation data according to CFrames | Roblox Creator Documentation

Print out CFrame.new(0, 0, 0) in your studio command line. You’ll see this:
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1. The rotational matrix looks like this:

1, 0, 0
0, 1, 0
0, 0, 1

This matrix is RightVector, UpVector, -LookVector: CFrame | Roblox Creator Documentation in case you ever wondered why -Z is forward, this is why. LookVector is negated in the cframe structure.

To get what you want to can do something like this:
CFrame.fromOrientation(cf:ToOrientation())
this will give you a cframe at origin with the same orientation as cf where cf is the cframe of the part.

what does this cf refer to??

This cf is the cframe of the part you want to move, or in your case it can be the primary part of the model. Something like model:SetPrimaryPartCFrame(CFrame.fromOrientation(model.PrimaryPart.CFrame:ToOrientation()))

So this is what I have now where do I place the code to set the orgin position to 0?

modelTarget:SetPrimaryPartCFrame(CFrame.fromOrientation(modelTarget.PrimaryPart:ToOrientation()))

That will already set the position to 0. It does this because ToOrientation returns the (approximate) angles required to recreate the orientation. fromOrientation creates a new CFrame with those angles, and by default it’s just at 0, 0, 0.

well this returns an error though.
ToOrientation is not a valid member of Part "Players.ZombieKicker7.PlayerGui.ViewportGui.ViewportFrame.Model.Main"

That’s because you need to use it on a cframe modelTarget.PrimaryPart.CFrame:ToOrientation()

To preserve the orientation (and avoid converting it to euler angles like the above posts suggest) you can do the following

local orientation = modelTarget:GetPrimaryPartCFrame()
modelTarget:SetPrimaryPartCFrame(CFrame.new(0, 0, 0) * (orientation - orientation.Position))
1 Like

oh yeah your right my bad lol.

Is there a problem with converting it to euler angles?

Euler angles are not a complete representations of orientations in 3D space, and mostly exist for people to think about orientations on a given plane. They have a lot of edge case issues, such as gimble locking and also use processing power to compute since they’re converting to and from angular space (which involves trig functions)

Both do work but I’ll go with your idea since I didn’t understand a lot of that except for euler = bad.

Hey while your here I have another question about CFrame and all that. Ill create a new post if you can help.

Sure, PM me the link. 20charsssssssssssssssssssss