CFrame (Property): Difference between revisions

From Goodblox Wiki
Jump to navigationJump to search
(Created page with "{{CatUp|Properties}} {{Property| name = CFrame |property = CFrame ''CFrame'' |description = The current Position, rotation, and several other properties...")
 
No edit summary
Line 5: Line 5:
|property = [[Scripting#CFrame|CFrame]] ''CFrame''
|property = [[Scripting#CFrame|CFrame]] ''CFrame''
|description = The current Position, rotation, and several other properties of an object.
|description = The current Position, rotation, and several other properties of an object.
|object = [[GBX.lua.FlagStand (Object)|Flagstand]], [[GBX.lua.Part (Object)|Part]], [[GBX.lua.Seat (Object)|Seat]], [[GBX.lua.SpawnLocation (Object)|SpawnLocation]]
|object = [[GBX.lua.BasePart (Object)|BasePart]]|}}
|}}
|}}


Line 13: Line 13:
Vector3 example:
Vector3 example:
<pre>
<pre>
game.Workspace.username.Torso.Position = Vector3.new(0,10,0)
workspace.username.Torso.Position = Vector3.new(0,10,0)
</pre>
</pre>


CFrame example:
CFrame example:
<pre>
<pre>
game.Workspace.username.Torso.CFrame = CFrame.new(Vector3.new(0,10,0))
workspace.username.Torso.CFrame = CFrame.new(Vector3.new(0,10,0))
</pre>
</pre>


Line 26: Line 26:
You want to try yourself at teleporting character models now?  Same as "Vector3.new" (see above), "CFrame.new" creates a new CFrame.
You want to try yourself at teleporting character models now?  Same as "Vector3.new" (see above), "CFrame.new" creates a new CFrame.
<pre>
<pre>
myself = game.Workspace.username
local myself = workspace.username
myself.Torso.CFrame = CFrame.new(Vector3.new(0,10,0))
myself.Torso.CFrame = CFrame.new(Vector3.new(0,10,0))
</pre>
</pre>
Line 35: Line 35:




CFrames themselves are one of the Basic Types available in Goodblox Lua. It can be called by using several different constructors.
CFrames themselves are one of the Basic Types available in GoodBlox Lua. It can be called by using several different constructors.
<!-- Yeah this formatting is awful, I'm putting it here for easier access. Needs to be cleaned up, don't have time right now -->
<!-- Yeah this formatting is awful, I'm putting it here for easier access. Needs to be cleaned up, don't have time right now -->



Revision as of 13:10, 20 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


See also

Vector3