CFrameデータ型
データ型日本語解説あり
ひとことで言うと
位置と向き(回転)を1つにまとめて表すデータ型です。パーツを回転させたり、向きを変えながら動かしたりするときに使います。
公式の説明(英語):A data type that represents both a 3D position and orientation.
CFrame.new(x, y, z) で位置を作り、CFrame.Angles(x, y, z) で回転(ラジアン)を作ります。2つをかけ算すると「その位置で、その向きに回す」になります。
使用例
Script置く場所:パーツの中
local RunService = game:GetService("RunService")
local part = script.Parent :: BasePart
part.Anchored = true
RunService.Heartbeat:Connect(function(deltaTime)
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(90) * deltaTime, 0)
end)Script置く場所:ServerScriptService
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 10, 0)
part.CFrame = CFrame.new(0, 10, 0) * CFrame.Angles(0, math.rad(45), 0)
part.Parent = workspace
local distance = (part.Position - Vector3.new(0, 0, 0)).Magnitude
print(distance)スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
コンストラクター(作り方)(16)
| 名前と書き方 | 説明 |
|---|---|
newCFrame.new() | 位置(と向き)を指定してCFrameを作ります。Returns a blank identity CFrame. |
newCFrame.new(pos: Vector3) | 位置(と向き)を指定してCFrameを作ります。Returns a CFrame with no rotation with the position of the provided Vector3. |
newCFrame.new(pos: Vector3, lookAt: Vector3) | 位置(と向き)を指定してCFrameを作ります。Returns a CFrame with the position of the first Vector3 and an orientation pointed toward the second. |
newCFrame.new(x: number, y: number, z: number) | 位置(と向き)を指定してCFrameを作ります。Returns a CFrame with a position comprised of the provided x, y, and z components. |
newCFrame.new(x: number, y: number, z: number, qX: number, qY: number, qZ: number, qW: number) | 位置(と向き)を指定してCFrameを作ります。Returns a CFrame from position (x, y, z) and quaternion (qX, qY, qZ, qW). |
newCFrame.new(x: number, y: number, z: number, R00: number, R01: number, R02: number, R10: number, R11: number, R12: number, R20: number, R21: number, R22: number) | 位置(と向き)を指定してCFrameを作ります。Returns a CFrame from position (x, y, z) with an orientation specified by the rotation matrix. |
lookAtCFrame.lookAt(at: Vector3, lookAt: Vector3, up: Vector3) | ある位置から、別の位置を向いたCFrameを作ります。Returns a CFrame with the position of the first Vector3 and an orientation pointed toward the second. |
lookAlongCFrame.lookAlong(at: Vector3, direction: Vector3, up: Vector3) | Returns a CFrame with the position of the first Vector3 and an orientation directed along the second. |
fromRotationBetweenVectorsCFrame.fromRotationBetweenVectors(from: Vector3, to: Vector3) | Returns a CFrame representing the orientation needed to rotate from the first Vector3 to the second, with the position set to zero. |
fromEulerAnglesCFrame.fromEulerAngles(rx: number, ry: number, rz: number, order: RotationOrder) | Returns a rotated CFrame from angles rx, ry, and rz in radians. Rotations are applied in the optional RotationOrder with a default of XYZ. |
fromEulerAnglesXYZCFrame.fromEulerAnglesXYZ(rx: number, ry: number, rz: number) | Returns a rotated CFrame from angles rx, ry, and rz in radians using RotationOrder.XYZ. |
fromEulerAnglesYXZCFrame.fromEulerAnglesYXZ(rx: number, ry: number, rz: number) | Returns a rotated CFrame from angles rx, ry, and rz in radians using RotationOrder.YXZ. |
AnglesCFrame.Angles(rx: number, ry: number, rz: number) | X・Y・Z軸のまわりの回転(ラジアン)からCFrameを作ります。Equivalent to Datatype.CFrame.fromEulerAnglesXYZ()|fromEulerAnglesXYZ(). |
fromOrientationCFrame.fromOrientation(rx: number, ry: number, rz: number) | Equivalent to Datatype.CFrame.fromEulerAnglesYXZ()|fromEulerAnglesYXZ(). |
fromAxisAngleCFrame.fromAxisAngle(v: Vector3, r: number) | Returns a rotated CFrame from a unit Vector3 and a rotation in radians. |
fromMatrixCFrame.fromMatrix(pos: Vector3, vX: Vector3, vY: Vector3, vZ: Vector3) | Returns a CFrame from a translation and the columns of a rotation matrix. |
プロパティ(12)
| 名前と書き方 | 説明 |
|---|---|
identityCFrame.identity: CFrame | An identity CFrame with no translation or rotation. |
PositionCFrame.Position: Vector3 | CFrameの位置(Vector3)。The 3D position of the CFrame. |
RotationCFrame.Rotation: CFrame | A copy of the CFrame with no translation. |
XCFrame.X: number | The **X** coordinate of the position. |
YCFrame.Y: number | The **Y** coordinate of the position. |
ZCFrame.Z: number | The **Z** coordinate of the position. |
LookVectorCFrame.LookVector: Vector3 | CFrameが向いている前の方向。The forward-direction component of the CFrame object's orientation, equivalent to the negated form of Datatype.CFrame.ZVector|ZVector. |
RightVectorCFrame.RightVector: Vector3 | The right-direction component of the CFrame object's orientation. |
UpVectorCFrame.UpVector: Vector3 | The up-direction component of the CFrame object's orientation. |
XVectorCFrame.XVector: Vector3 | Equivalent to Datatype.CFrame.RightVector|RightVector. |
YVectorCFrame.YVector: Vector3 | Equivalent to Datatype.CFrame.UpVector|UpVector. |
ZVectorCFrame.ZVector: Vector3 | The Z component of the CFrame object's orientation. Equivalent to the third column of the rotation matrix. |
メソッド(18)
| 名前と書き方 | 説明 |
|---|---|
InverseCFrame:Inverse(): CFrame | Returns the inverse of the CFrame. |
LerpCFrame:Lerp(goal: CFrame, alpha: number): CFrame | Returns a CFrame interpolated between itself and goal by the fraction alpha. |
OrthonormalizeCFrame:Orthonormalize(): CFrame | Returns an orthonormalized copy of the CFrame. |
ToWorldSpaceCFrame:ToWorldSpace(...: Tuple<CFrame>): Tuple<CFrame> | Receives one or more CFrame objects and returns them transformed from object to world space. |
ToObjectSpaceCFrame:ToObjectSpace(...: Tuple<CFrame>): Tuple<CFrame> | Receives one or more CFrame objects and returns them transformed from world to object space. |
PointToWorldSpaceCFrame:PointToWorldSpace(...: Tuple<Vector3>): Tuple<Vector3> | Receives one or more Vector3 objects and returns them transformed from object to world space. |
PointToObjectSpaceCFrame:PointToObjectSpace(...: Tuple<Vector3>): Tuple<Vector3> | Receives one or more Vector3 objects and returns them transformed from world to object space. |
VectorToWorldSpaceCFrame:VectorToWorldSpace(...: Tuple<Vector3>): Tuple<Vector3> | Receives one or more Vector3 objects and returns them rotated from object to world space. |
VectorToObjectSpaceCFrame:VectorToObjectSpace(...: Tuple<Vector3>): Tuple<Vector3> | Receives one or more Vector3 objects and returns them rotated from world to object space. |
GetComponentsCFrame:GetComponents(): Tuple | Returns the values x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, and R22, where x y z represent the position of the CFrame and R00‑R22 represent its 3×3 rotation matrix. |
ToEulerAnglesCFrame:ToEulerAngles(order: RotationOrder): number, number, number | Returns approximate angles that could be used to generate the CFrame using the optional RotationOrder. |
ToEulerAnglesXYZCFrame:ToEulerAnglesXYZ(): number, number, number | Returns the approximate angles (in radians) that could be used to generate the CFrame using RotationOrder.XYZ. |
ToEulerAnglesYXZCFrame:ToEulerAnglesYXZ(): number, number, number | Returns the approximate angles (in radians) that could be used to generate the CFrame using RotationOrder.YXZ. |
ToOrientationCFrame:ToOrientation(): number, number, number | Returns the approximate angles (in radians) that could be used to generate the CFrame using the YXZ rotation order. |
ToAxisAngleCFrame:ToAxisAngle(): Vector3, number | Returns a tuple containing a unit Vector3 axis and a rotation angle in radians. |
componentsCFrame:components(): Tuple | Equivalent to Datatype.CFrame:GetComponents(). |
FuzzyEqCFrame:FuzzyEq(other: CFrame, epsilon: number): bool | Returns true if the other CFrame is sufficiently close to this CFrame in both position and rotation. |
AngleBetweenCFrame:AngleBetween(other: CFrame): number | Returns the angle, in radians, between the orientation of one CFrame and another. |
CFrameを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(CFrame)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。