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!
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.
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 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)
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?