What is :vectorToObjectSpace() used for?

The title says it all. So basicly what is :vectorToObjectSpace() V.S. :vectorToWorldSpace.
My question is what are their uses, and why do we have them, and what is the difference, and how to use them.

3 Likes

World space is based off the origin, so it’s where is this position relative to (0,0,0).
Object space is based off an object. So where is that position relative to the position of some object.

For example - if you have two positions, one at (9,9,9) and the other at (6,6,6), then:

(9,9,9) has a world space of (9,9,9).
(9,9,9) has an object space relative to (6,6,6) of (3,3,3) (the offset).

I think they’re useful in situations where you’re comparing positions but somebody else would be a better source on that.

16 Likes

But why does (9, 9, 9) have on object space of: (6,6,6)

Say you had two blocks; One at (9,9,9) and one at (6,6,6). The block at (9,9,9) has an object space relative to (6,6,6) of (3,3,3) which is just (9-6,9-6,9-6).

3 Likes

Ahh… now I understand it, so basicly it gives you the difference between those two objects.

Could someone just clarify weather or not I understand correct though?

2 Likes

Both VectorToObjectSpace and VectorToWorldSpace do not use the position of the CFrame.

EDIT: When I refer to position of the CFrame, I’m referring to CFrame.Position. v3 refers to Vector3.new

This is because CFrame:VectorToObjectSpace(v3) does the equivalent of:
(CFrame:inverse() - CFrame:inverse().Position) * v3
where the position of (CFrame:inverse() - CFrame:inverse().Position) is set to Vector3.new(0, 0, 0) because CFrame’s position was offset by it’s negative position and the sum of something and it’s negation is 0. This new CFrame calculated in the brackets is then multiplied with v3.

Similar reasoning for why the position of the CFrame does not affect the result for CFrame:VectorToWorldSpace(v3).

What does affect the result is the rotation (or orientation) of the CFrame.
A good way to think of it is, each CFrame (ignoring it’s positional part), represents a rotation.

Normally, in world space, every position is represented by some multiple of v3(1,0,0), v3(0,1,0), and, v3(0,0,1). For example, the position v3(8.4, 4, 7) is 8.4*v3(1,0,0) + 4*v3(0,1,0) + 7*v3(0,0,1).
However, now imagine the world from the perspective of a particular CFrame in which the up/down, right/left, and back/forward directions are different. Now, the “Up”-direction is no longer v3(0,1,0) but instead CFrame.UpVector. Similar changes for the right and forward directions. In this “rotated”-world, what are the coordinates of v3(8.4, 4, 7), and by that I mean, for what values a, b, c, does
a*CFrame.RightVector + b*CFrame.UpVector + c*CFrame.LookVector equal the same as v3(8.4, 4, 7)

It’s ultimately returning the coordinates of a particular vector3 from the perspective of a world in which you have a different global rightvector, upvector, and lookvector. Before, in worldspace, coordinates were represented as multiples of v3(1,0,0) and v3(0,1,0) and v3(0,0,1). Now, they’re being represented as multiples of CFrame.RightVector and CFrame.UpVector and CFrame.LookVector. This is what it means to represent a vector relative to a particular CFrame.

So, in that world from the perspective of the CFrame you use VectorToObjectSpace on, what are the coordinates of v3(8.4, 4, 7)?

Well, the coordinates will be v3(a, b, c) as each of a, b, and, c represent what multiple.

Overall, this means that CFrame:VectorToObjectSpace(v3(8.4, 4, 7)) gives v3(a, b, c).
I.e. It’s taking a vector from the coordinates of world space and giving it in the coordinates of object space where the object space is that “rotated”-space of CFrame.

CFrame:VectorToWorldSpace(v3(a,b,c)) will give v3(8.4, 4, 7) because it takes that position(vector) in object-space back into world space, essentially doing the inverse of VectorToObjectSpace.

42 Likes

one use for the function would be making a conveyer belt