Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is world and object space?

Asked by 5 years ago
Edited 5 years ago

I was learning CFrame, and I came across the following:

toWorldSpace

toObjectSpace

pointToWorldSpace

pointToObjectSpace

vectorToWorldSpace

vectorToObjectSpace

As I was learning, it got really confused on what is world and object space.

1 answer

Log in to vote
3
Answered by
RayCurse 1518 Moderation Voter
5 years ago
Edited 5 years ago

An Analogy

If I were to give you directions to a certain location on the earth, I could give you specific longitude and latitude coordinates. Or I could say that the specified location is "5 km north of the convenience store". This relates to object and world space. Giving longitude and latitude coordinates is analogous to world space and giving directions relating to the school is analogous to object space.

Explanations and Examples

Each of the CFrame methods you outlined are explained and given with examples.

CFrame:toWorldSpace(cf)

This method converts a cframe in object space to a cframe in world space. In other words it takes cf (which is relative to CFrame) and returns a result that is relative to the origin. For example, if I have a cframe called cf1 which is defined to be CFrame.new(0 , 10 , 0) and I have another cframe relative to cf1 called cf2 which is CFrame.new(1 , 0 , 0), cf1:toWorldSpace(cf2) will return a cframe in world space that is relative to the origin/identity cframe.

CFrame:toObjectSpace(cf)

This method does the exact opposite. Given a CFrame (let's call it cf1), and an input CFrame (call it c2), it will return a result representing the cframe cf2 is in relative to cf1. For example, if an input CFrame defined CFrame.new(5 , 1 , 3) is given, CFrame.new(1 , 1 1):toObjectSpace(cf) will return CFrame.new(4 , 0 , 2) because that is the CFrame the input is in relative to CFrame.new(1 , 1 , 1)

CFrame:pointToObjectSpace(v3) and CFrame:pointToWorldSpace(v3)

These methods just do the same thing as CFrame:toObjectSpace(cf) and CFrame:toWorldSpace(cf) respectively but work with Vector3 inputs instead.

CFrame:vectorToWorldSpace(v3)

This method is a little harder to visualize because it takes rotation into account. Keep in the mind that in this case, the input Vector3 represents a direction and not a position. Given a CFrame and a Vector3 (relative to the CFrame's orientation), this method will return a new Vector3 that represents the rotation in world space. For example, if I have a CFrame that is defined as CFrame.Angles(math.pi , 0 , 0) (this CFrame's y axis is upside down) and I call cframe:vectorToWorldSpace(Vector3.new(0 , 1 , 0)), it will return Vector3.new(0 , -1 , 0). This is because the original vector is pointing upwards relative to the CFrame. Since the CFrame itself is upside down, vectorToWorldSpace(v3) returns the "actual" direction the vector is pointing in.

CFrame:vectorToObjectSpace(v3)

This method reverses what vectorToWorldSpace() does. It will rotate a vector in world space so that it matches up with the rotation of the said CFrame.

0
In Roblox, what would be world and what would be object? I was thinking that Vector3 is world, and CFrame is world. User#24541 10 — 5y
0
You're thinking about this the wrong way. If you're familiar with the Cartesian grid (you very likely have if you know about xy coordinates), you'll know that the origin is located at (0 , 0). Similarly, Roblox has a similar concept except it's in 3D. World space is relative to (0 , 0 , 0) and object space is relative to an arbitrary position. Of course with CFrames, rotation follows a similar con RayCurse 1518 — 5y
0
With rotation, the "origin" would be no rotation at all, and rotation in object space will just mean offsetting from another arbritrary rotation. Remember that when talking about rotation in object space, all axes can rotate freely (e.g. the y axis (up axis) could be upside down because of its rotation). RayCurse 1518 — 5y
0
I get it, but when you said "giving directions relating to the school," what do you mean? User#24541 10 — 5y
View all comments (3 more)
0
And also when will those CFrame functions be useful for? User#24541 10 — 5y
0
I mean that the school would be an arbitrary position. "Go 5 km north of the school" means different places depending on where you are in the world and which school you're talking about. "Go to these specific coordinates 15°N 30°E" will mean the exact same place no matter where you are in the world. RayCurse 1518 — 5y
0
These CFrame methods are useful when you want a position relative to something else. For example, if you want to place an orb on top of the player's head, you would use object space because the position you want is relative to the player head. There are wide range use of cases and you'll inevitably bump into one as you practice and develop your own games. These are essential tools. RayCurse 1518 — 5y
Ad

Answer this question