But then if I rotate the part, the relative Position changes. Even though in world space the parts Position doesn’t change when you change the rotation.
I put one part at Worldspace Position (-243,6,3) unrotated and one part rotated.
The Y and the Z axis are swapped
I assume the reason for this is when multiplying the CFrames it takes the parts rotation into account.
How can I get a Parts correct Position and Rotation relative to an Object even if it’s rotated?
No I don’t want to ignore the Orientation I just don’t want it to affect the Object Space Position
As in I want it to act like a part in world space, if a part is at coordinates (0,8,0) then I rotate it, it doesn’t then make the Position (0,0,8). It keeps the Position (0,8,0) and adds to the Orientation.
I’m think I’m confused with the :ToWorldSpace function can you replace the CFrame.new and Vector3.new with “ObjectSpace” or “WorldSpace” or “origin.CFrame”?
Also doesn’t it take a CFrame as a parameter not a Vector3?
So I take Mouse.Hit which is in Worldspace and place a Part there, then I convert Mouse.Hit into ObjectSpace relative to origin.CFrame, then I convert the ObjectSpace into world space and it’s in a completely different Position
local cframe = Mouse.Hit
local part1 = Instance.new("Part")
part1.CFrame = cframe
local objectspace = cframe:ToObjectSpace(origin.CFrame)
local part2 = Instance.new("Part")
part2.CFrame = objectspace:ToWorldSpace(origin.CFrame)
I think I am getting ToObjectSpace wrong or ToWorldSpace wrong, but I don’t think that solves the original question from the OP about why the object space position changes on rotate.
This would be more obvious if roblox didnt use the weird ToObjectSpace and ToWorldSpace functions
c = a:ToObjectSpace(b) is the same as c = a:Inverse() * b b = a:ToWorldSpace(c) is the same as b = a * c
When you do c = a:Inverse() * b to get object space relative to a, its quite obvious that all you have to do is multiply a by the whole thing to extract b
Multiply both sides by a a(c) = a(a:Inverse() * b)
The as cancel out a*c = b
This isnt self explanatory at all when roblox creates these “easy to use” cover functions instead of the actual math
So in your case, when youre doing:
objectspace = cframe:ToObjectSpace(origin.CFrame)
Youre actually doing: objectspace = cframe:Inverse() * origin.CFrame
You can then infer from this the formula you would use to get the origin.CFrame, or the original CFrame back by itself
You would obviously just multiply both sides by cframe cframe*(objectspace) = cframe*(cframe:Inverse() * origin.CFrame
cframe then cancels out and youre left with the formula you need cframe * objectspace = origin.CFrame
Or, in terms of robloxs bad functions originCFrame = cframe:ToWorldSpace(objectspace)