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

What is the difference between CFrame and Vector3 ?

Asked by 9 years ago

They both hold x, y and z so what is the difference or which one should be used?

Vector3 CFrame

2 answers

Log in to vote
7
Answered by
TaslemGuy 211 Moderation Voter
9 years ago

A Vector3 is a location in space. It has an x, y, and z coordinate.

CFrames are locations and orientations in space.

So, for example, if I tell you that my position is (4, 5, 0), you know where I am, but you don't know which way I am facing.

So if you want to set an object's orientation, you have to use CFrames, since Vector3s do not contain any direction information.

You can construct CFrames in several ways:

CFrame.new( pos )

Where pos is a Vector3, creates a CFrame at that position with the "standard" orientation.

CFrame.new( pos, toward ) where both pos and toward are Vector3s, creates a CFrame at the location poswith a front that faces toward toward.

So CFrames contain a lot more information. Internally, they're 4x4 matrices (Vectors are 3x1 matrices).

A totally unrelated issue is how Roblox handles assigning CFrame and Position in parts.

When you assign Position or Size, parts will automatically "exit" anything they get stuck in, by traveling straight upward. So, for example, if you try to bury a brick underground, it won't work, it will just sit on top.

However, assigning CFrame doesn't do this extra "no intersection" stuff, so it will happily bury things if you ask it to.

Ad
Log in to vote
0
Answered by 9 years ago

From my own personal experience, it seems that CFrame is more precise. If you use Vector3 and it clips with an object, it won't go through the part it clips, it will round and put it above/below the part.

CFrame, however, wil allow you to clip an object.

Note: I do not know this for fact, this is just based on my own personal experiences.
3
You're right about the clipping, but it's not really a matter of precision. It isn't rounding, the behavior just causes parts to automatically avoid intersection when you assign Position. The much, much bigger difference between the two is that CFrames contain orientation ("rotation") information, while Vector3s do not. CFrames are internally stored as 4x4 matrices (16 values) while Vector3s are ( TaslemGuy 211 — 9y

Answer this question