ToWorldSpace - ToObjectSpace

Hello!
I was wondering what can I use CFrame:ToObjectSpace() and CFrame:ToWordlSpace()

Also, what’s the difference, and what those are?

What can I do with them? Is it hard to understand?

1 Like

ToWorldSpace gets a new CFrame from a relative CFrame to the world and another cframe. It basically “adds” two CFrames together and in the direction of where the CFrame is. It is equivalent to Cframe * cf

local relativeCF = CFrame.new(0, 0, -5)
local worldCf = CFrame.new(0, 10, 0) * CFrame.Angles(0, math.pi / 4, 0)
local newCF = worldCF:ToWorldSpace(worldCf) -- this basically makes a new CFrame that is 5 studs away in the negative z-axis of the part, which gives you a CFrame 5 studs in front of the rotated cframe

ToObjectSpace is kinda the opposite - it gets a CFrame that is relative to two CFrames relative to the world, equivalent to CFrame:inverse() * cf. It can be used to get the CFrame needed to position and orient a new cframe at a point. A specific example of this is positioning your arm a point in the world - say you want to always keep the Right Arm of the player at 0, 0, 0 (origin), you can do:

local target = CFrame.new() -- identity cframe which is equal to 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
armMotor6D.C0 = torso.CFrame:ToObjectSpace(target)
armMotor6D.C1 = CFrame.new() -- just so this doesn't have any influence on the cframe

This question has also been asked on the devforum tho - I implore you to search the devforum before making a post

2 Likes