Why don't I see any difference between CFrame and Vector3?

I’ve looked at documentation and other questions for this on the devforum but I still don’t understand.

For example I have this for Vector3:

local part = script.Parent
part.Position = Vector3.new(0,0,5)

And this for CFrame:

local part = script.Parent
local newCFrame = CFrame.new(0,0,5)
part.CFrame = newCFrame

But they both do the same thing.

I’ve read on this devforum and I was told CFrame is supposed to move(& orientate at the same time, but i didn’t add this to the code) the part relative to where the part is at the time

and Vector3 sets a part’s position based on the actual in game world (relative to the world’s origin (0,0,0)

So why do these two do the same thing, I thought CFrame was going to move it 5 to where it originally was.

I understand that the code is setting the part’s CFrame to where it is in the world, but then why would I use CFrame if If I could just use Vector3?

Could someone please explain, am I missing something?

2 Likes

fast answer, cframe is also relative to (0, 0, 0) aka the origin also known as World Space

And if you wanna have a part be offset relative to a CFrame you can just do some easy multiplication

local part = path

part.CFrame *= CFrame.new(0, 0, 5)
2 Likes

oh okay, must’ve read it wrong then

what is the difference between these two codes or is there no difference?
& if there’s no difference, why would should I use CFrame instead of Vector3 if I am not orientating something?

1 Like

A multitude of reasons out there but if you wanna get what direction the player is facing, you can get the LookVector (hrp.CFrame.LookVector)

1 Like

A CFrame is the combination of an Instance’s Position and Rotation. The Position property just points back to the CFrame’s Position value

When you’d use one or the other just depends on your use-case and what you need. Roblox has an article on this that goes into more detail on different uses:

3 Likes

One difference is that if you are working with welds if you are using .Position you will only move that part instead of the whole assembly.

2 Likes

was this already explained? don’t know don’t care

cframe is both position and orientation

vector3 is position only

2 Likes

so if I got it right, essentially the code i provided does achieve the same thing

however vector3 and cframes are still different
and i’ll use vector3 when it comes to only the manipulating position
then cframes when i want to manipulate both position and orientation at the same time?

1 Like

That’s pretty much how I use them

2 Likes

Hey! Basically, CFrame allows you to do more advanced positioning for BaseParts, for example, take this piece of code:

local MyPart = workspace.Part

MyPart.Position = Vector3.new(0,5,0) -- This will set the part's coordinates to (X: 0, Y: 5, Z: 0)

--[[
But, for example, if you want the part to be facing at something, 
you'd need to do a much more complex process with Vector3s and Orientation values, 
instead CFrame allows you to use this function]]

Part.CFrame = CFrame.LookAt(Vector3.new(0, 5 ,0), Vector3.zero) 
-- The line above will not only set the part at the coordinates (X: 0, Y: 5, Z: 0),
-- It'll also make the part's front side face the Coordinate  (X: 0, Y: 0, Z: 0)!

There are also other case usages for CFrame, for example, positioning something in front of something else, without having to worry about the orientation

local MyPart = workspace.Part
local MyOtherPart = workspace.OtherPart

MyPart.CFrame = MyOtherPart.CFrame * CFrame.new(0,0,-5) 
-- This line will position MyPart 5 studs in front of the Other part's position

I hope any of this information is useful to you! CFrame can be the solution to multiple coding problems or workarounds, so you’ll most likely always find a chance to use them.

Roblox actually has a page where they explain how CFraming works (with images), I encourage you to check it out to further more understand its behavior

1 Like

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