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

[Resolved]Can Someone Explain To Me CFrame:Inverse(), :toObjectSpace() and :toWorldSpace() ?

Asked by 6 years ago
Edited 6 years ago

I cant really figure out whats CFrame:Inverse(), :toObjectSpace() and :toWorldSpace() and really need an explanation.

Can someone pls explain?? Thanks, I also need a little explanation on the difference between Vector3.new() and CFrame.new().

All helps will be greatly appreciated. Will accept the most suitable answer.

0
no. this is what the wiki is for. DinozCreates 1070 — 6y
2
No. A member of the community can explain it. This question falls under concepts to provide a more understandable response. M39a9am3R 3210 — 6y
0
i think its too broad a question. i've seen many times where more pointed questions were closed, should aim for consistency if anything. DinozCreates 1070 — 6y
0
Note that the wiki has a section on trying to explain the difference between Object space and World space here: http://wiki.roblox.com/index.php?title=CFrame#Local_and_World_Space chess123mate 5873 — 6y

3 answers

Log in to vote
1
Answered by
Destrings 406 Moderation Voter
6 years ago
Edited 6 years ago

Let's start with coordinate systems. A coordinate system is just a way to describe the position of an object in some space.

ROBLOX is, obviously, three dimensional, so to describe the position you need three numbers. These numbers can be interpreted as the distance along each axes, so (3, 5, 6) would mean 3 studs right (X axis), 5 studs up (Y axis) , and 6 studs forward (Z axis). This requires a point of reference, i.e where to start before applying these movements. This point of reference is called the origin of the coordinate system, and is represented by the (0,0,0) coordinate.

Those three numbers can be efficiently represented and computed upon using vectors. Which is what Vector3 class provides, a way to manipulate positions in 3D space along with common vector operations such as cross and dot product.

However vectors can only represent position, not orientation. You would think you need 3 more numbers to define orientation (the degree to rotate along each axis applied in sequence), and it would be correct, those are called Euler Angles, however to represent them efficiently and be able to make quick computations with them you use what we call rotation matrices.

These are provided by roblox with the CFrame class, name standing for Coordiante Frame, and they can encode orientation and apply rotations efficiently.

Now let's say you have a ball in position (3,0,2), as I mentioned above, this vector represents the position with respect with to the origin of a coordinate system. The default coordinate system in ROBLOX is called world space, where every object shares the same origin. However what if you need to know how far a character standing at (3,0,3) is from the ball?, you can compute it easily enough with simple math and get (0,0,1) studs from the ball. What you did there was actually convert the character position to object space, particularly to the ball's object space, and as the name implies is just a coordinate system where the origin is now the position of the ball, so everything is represented as being away from the ball instead of the world origin.

This was done easily enough since we didn't care about orientation, when you take into account orientation the math gets complicated (for those interested is just some linear algebra and trigonometry), so ROBLOX handles that for you with the methods toObjectSpace and toWorldSpace, where given a CFrame we convert it to the object space of another CFrame, or viceversa with toWorldSpace.

Inverse is used under the hood when performing those computations, as I mentioned before these computations involve linear algebra, but in layman's terms if you move an object with a CFrame, Inverse gives you the CFrame to move the object back to starting place.

0
Thanks. Now i understand abit about it xD Yokohane 50 — 6y
Ad
Log in to vote
0
Answered by
Vathriel 510 Moderation Voter
6 years ago
Edited 6 years ago

CFrame:toObjectSpace(arg) takes the CFrame (in world coordinates) and translates it to the coordinates of arg (as if arg was the origin of the game).

CFrame:toWorldSpace(arg) takes the CFrame relative to arg and translates it back to coordinates relative to the origin of the game.

CFrame:Inverse() as far as I know inverts the matrix of a CFrame. Which you'd have to know more about matrix math to deal with.

0
afaik, CFrame:ToObjectSpace() and CFrame:ToWorldSpace() work the other way around. self is the origin and the argument(s) are the positions and orientations BenSBk 781 — 6y
0
I was testing with this just yesterday and it seemed a:ToObjectSpace(b) where b was the origin was what worked, similarly a:ToWorldSpace(b) was what worked. I can try it again in the morning though, unless you'd like to. Vathriel 510 — 6y
0
:Inverse() lets you "divide" by a cframe (by multiplying by its inverse). ex, if you have a cframe that will rotate a part, the inverse of that cframe would undo that rotation. chess123mate 5873 — 6y
0
in other words you have to be at least in high school to understand how matrices work DeceptiveCaster 3761 — 6y
View all comments (2 more)
0
Well, you can study about matrices, but the essence of these transformations are more properly described by Linear Algebra. Indecyzo 31 — 6y
0
xD still not quite understand Yokohane 50 — 6y
Log in to vote
0
Answered by 6 years ago

Thank You @Destrings & @Vathriel for answering and trying to help! Also, thank you to all of you guys who commented. Appreciated :) Have a good day!

Answer this question