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

Should I be using Position, CFrame or Vector3 for setting the position of an object? [closed]

Asked by 5 years ago

Just a quick question here. Should I set the location of an object via the Position, CFrame or Vector3? Example:

local part = Instance.new("Part")
part.Position = Vector3.new(0, 1, 1)

or:

local part = Instance.new("Part")
part.CFrame = Vector3.new(0, 1, 1)

or:

local part = Instance.new("Part")
part.Vector3 = Vector3.new(0, 1, 1)

or: Is there a better way I have yet to think of? Thanks!

0
part.Vector3? Use CFrame User#19524 175 — 5y
0
I don't even know if some of these methods are valid. User#21908 42 — 5y
0
Or if there are way better methods. User#21908 42 — 5y
0
thonk User#19524 175 — 5y
0
use CFrame greatneil80 2647 — 5y

Locked by User#19524

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

There are different ways of setting the positioning of a BasePart. The most common and useful way is to use .CFrame.

Trying to set the Vector3 of a part would error, because BasePart's don't have a Vector3 property.

You can check the properties of a BasePart here.

Parts, MeshParts, Unions, and basically anything with a hitbox is a BasePart

Using .Positon

When you set the .Position property of a BasePart, it sets the center of the part to the position specified, unless this would cause parts of the BasePart to be inside of other BaseParts, causing collision overlaps, in which case the part will be placed upwards along the Y axis until there are no longer overlaps.

This means sometimes when setting the position of a BasePart, that part won't be placed where you want it to be placed. This can sometimes be useful if you don't want the BasePart to be played inside another part.


Using .CFrame

Using CFrame is the way I'd recommend not knowing the situation, as it's generally the right choice. CFrame will place the BasePart inside other objects even if there are collisions.

CFrame is not just the position, but also the orientation of a BasePart. CFrames can be complicated for some people, but because we're not talking about the rotation of the BasePart, it's pretty east to understand.

local part;

part.CFrame = CFrame.new(x, y, z)
This causes the orientation of the part to be 0, 0, 0

If you have any more questions, feel free to ask.

1
Good job. Upvote! User#19524 175 — 5y
0
Works. Thanks so much! User#21908 42 — 5y
0
Long time no see old pal happy greatneil80 2647 — 5y
Ad