Clearer descriptions on all types of object space functions and where to use them?

CFrame:ToObjectSpace()
CFrame:ToWorldSpace()
CFrame:PointToObjectSpace()
CFrame:PointToWorldSpace()
CFrame:VectorToObjectSpace()
CFrame:VectorToWorldSpace()

The following functions are very much confusing me, in my head I understand I want to convert a position in world space ( for example a position that may be 10 studs away from the user on the X, but 100 studs from the origin ) to object space, but I’m beyond confused, using PointToObjectSpace (as I imagine I would since I’m converting World to Object, right? gives me more arbitrary results which aren’t correct.

Very confusing, please help.

1 Like

Update, I was using VectorToObjectSpace instead of PointToObjectSpace, so I’ve actually got it working now, but on another note, could anyone give me a quick rundown on the use case scenarios on these functions?

I think I somewhat understand VectorToObjectSpace now that I’ve seen what PointToObjectSpace does (and their partners ToWorldSpace).

But the core :ToObjectSpace and :ToWorldSpace seem to still confuse me so any clear ups on that would be awesome.

1 Like

An example of both to object space and to world space is with the door hinge example.

Commonly used to get the rotation and position CFrame difference from CFrame A to B,

An example of the rotational difference

1 Like

Digging deeper, it seems kind of weird as if the ToObjectSpace and ToWorldSpace functions are almost mixed up?

The likes of this

local redBlock = game.Workspace.RedBlock
local blueCube = game.Workspace.BlueCube
 
local offsetCFrame = CFrame.new(0, 2, 0)
redBlock.CFrame = blueCube.CFrame:ToWorldSpace(offsetCFrame)

Taken from the wiki, it places the redBlock 2 studs above the blueCube, shouldn’t we be using ToObjectSpace for this?

2 Likes

Basically, ToObjectSpace is like subtraction.
So CFrameA:ToObjectSpace(CFrameB) will give you the offset of CFrame B from CFrame A, similar to how 2 is the difference of 10 - 8 (8 is offsetted by 2 from 10, ignore the direction). This also means that if you were to add the result of CFrameA:ToObjectSpace(CFrameB) to CFrame A, it will give you CFrame B.

Meanwhile, ToWorldSpace is more like addition.
CFrameA:ToWorldSpace(CFrameB) will add CFrame B to CFrame A, similar to how 10 is the sum of 8 + 2 (8 offsetted by 2 is 10). In other words, if you were to subtract CFrame B from CFrameA:ToWorldSpace(CFrameB), it will give you the original CFrame A without the offset of CFrame B.