Question about CFrame:ToObjectSpace - why do I get a negative relative position?

Hello
I have 2 parts one above another, no rotations:
GreenPart with position 10, 8, 5
OrangePart with position 10, 11, 5

I want to see what is the position of the OrangePart in relation to the GreenPart
When I call

local cf =  workspace.OrangePart.CFrame:ToObjectSpace(workspace.GreenPart.CFrame)
print(cf.Position)

I get 0, -3, 0
However I expect to get 0, 3, 0 , because I am translating the CFrame of the OrangePart in the coordinate system of the GreenPart and the OrangePart is 3 studs above it.

What do I miss here?

Thanks

I think it needs to be by worldspace because now it’s measuring the orange part’s relation to the green which is -3.
Of couse this is only if you want the distance measured according to the orientation of the world’s x, y, & z axes.

A:ToObjectSpace(B) does not convert A to Bs coordinate system, it does the opposite. It converts B to As coordinate system. Or in other words, it computes “B relative to A”. “GreenPart relative to OrangePart” is (0, -3, 0) (assuming OrangePart is not rotated), so you’re actually getting the expected output.

1 Like

This is from Roblox docs:

" To find the CFrame of the football relative to the blue player:
footballCF:ToObjectSpace(bluePlayerCF)"

In this example are we converting the ball’s position to player’s coordinate system or we are converting player’s position to ball’s coordinate system?

You’re getting the ball’s CFrame relative to the player’s CFrame, which is the same as seeing the ball in the player’s coordinates system.

The player is positioned at 10,8,5
The ball is positioned at 10, 11, 5 (3 studs above the player)

What should be the position of the ball in players coordinate system?
0, 3, 0
or
0, -3, 0
?

It should be 3 studs above the player then, though Roblox may see it the opposite way.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.