CFrame (Property): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{CatUp|Properties}} | {{CatUp|Properties}} | ||
{{Property| | {{Property| | ||
name = CFrame | name = CFrame |
Latest revision as of 21:48, 23 September 2021
Property | |
---|---|
Name | CFrame |
Property | CFrame CFrame |
Description: | The current Position, rotation, and several other properties of an object. |
In Object: | BasePart |
CFrame
CFrame stands for Coordinate Frame. You can change a character's position, which way it is facing, its rotation, and other things using this property. The difference between teleporting things with Vector3 and things with CFrame is that CFrame takes anything welded to the object along with it. Say you want to teleport yourself to 0,10,0:
Vector3 example:
workspace.username.Torso.Position = Vector3.new(0,10,0)
CFrame example:
workspace.username.Torso.CFrame = CFrame.new(Vector3.new(0,10,0))
Notice when you use Vector3 alone, your torso gets warped, but that is all. When you use CFrame combined with Vector3, your whole character gets transferred. Why am I using Vector3 in a CFrame? In this situation, the CFrame is looking for the x, y, and z. If you read the Vector3 segment, you would know what each vector is.
Creating New CFrames
You want to try yourself at teleporting character models now? Same as "Vector3.new" (see above), "CFrame.new" creates a new CFrame.
local myself = workspace.username myself.Torso.CFrame = CFrame.new(Vector3.new(0,10,0))
There's the variable noting myself. I go to myself and choose my Torso because the torso holds all the welds and snaps, and it is the main component of the character's coordinate frame. Instead of using ".Position", I use "CFrame". I am not changing its position anymore, I'm changing its whole Cframe. There is the "CFrame.new" statement, now inside the parentheses are the three vectors, x, y, and z.
Constructors
CFrames themselves are one of the Basic Types available in GoodBlox Lua. It can be called by using several different constructors.
Constructor | Description |
---|---|
new() |
Creates an identity CFrame |
new(v) |
Creates CFrame from offset Vector3 v |
new(v, l) |
Creates CFrame from offset Vector3 v looking at point l |
new(x, y, z) |
Creates CFrame from offset (x, y, z) |
new(x, y, z, qx, qy, qz, qw) |
Creates CFrame from offset (x, y, z) and quaternion (qx, qy, qz, qw) |
new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22) |
Creates CFrame from offset (x, y, z) and rotation matrix (R00, R01, R02, R10, R11, R12, R20, R21, R22) |
fromEulerAnglesXYZ(x, y, z) |
Creates a rotated CFrame (x, y, z) in radians |
fromAxisAngle(v, r) |
Creates a rotated CFrame from a unit vector and a rotation in radians |
Property | Type | Description |
---|---|---|
p |
Vector3 | the translation |
x |
number | the x-component of translation |
y |
number | the y-component of translation |
z |
number | the z-component of translation |
lookVector |
Vector3 | returns the facing direction along each axis |
Member Function | Description |
---|---|
CFrame inverse() |
returns the inverse of this CFrame |
CFrame toWorldSpace(CFrame) |
returns a CFrame transformed from Object to World coordinates. Also works with tuples |
CFrame toObjectSpace(CFrame) |
returns a CFrame transformed from World to Object coordinates. Also works with tuples |
Vector3 pointToWorldSpace(Vector3) |
returns a Vector3 transformed from Object to World coordinates. Also works with tuples |
Vector3 pointToObjectSpace(Vector3) |
returns a Vector3 transformed from World to Object coordinates. Also works with tuples |
Vector3 vectorToWorldSpace(Vector3) |
returns a Vector3 rotated from Object to World coordinates. Also works with tuples |
Vector3 vectorToObjectSpace(Vector3) |
returns a Vector3 rotated from World to Object coordinates. Also works with tuples |
Operator | Description |
---|---|
CFrame * CFrame |
returns composition of two CFrames |
CFrame * Vector3 |
returns Vector3 transformed from Object to World coordinates |
CFrame + Vector3 |
returns CFrame translated by Vector3 |
CFrame - Vector3 |
returns CFrame translated by -Vector3 |