Vector3データ型
データ型日本語解説あり
ひとことで言うと
3つの数(X・Y・Z)で、位置・大きさ・方向などを表すデータ型です。Vector3.new(0, 10, 0) のように作ります。
公式の説明(英語):Represents a 3D value with a direction and magnitude.
Xは左右、Yは上下、Zは前後の方向を表します。Vector3どうしは足し算・引き算ができ、Magnitudeで長さ(距離)を求められます。
使用例
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)で確認しています。
コンストラクター(作り方)(3)
| 名前と書き方 | 説明 |
|---|---|
newVector3.new(x: number, y: number, z: number) | X・Y・Zを指定してVector3を作ります。Returns a new Vector3 from the given x, y, and z components. |
FromNormalIdVector3.FromNormalId(normal: NormalId) | Returns a new Vector3 in the given direction. |
FromAxisVector3.FromAxis(axis: Axis) | Returns a new Vector3 for the given axis. |
プロパティ(10)
| 名前と書き方 | 説明 |
|---|---|
zeroVector3.zero: Vector3 | すべて0のベクトル。A Vector3 with a magnitude of 0. |
oneVector3.one: Vector3 | A Vector3 with a value of 1 on every axis. |
xAxisVector3.xAxis: Vector3 | A Vector3 with a value of 1 on the **X** axis. |
yAxisVector3.yAxis: Vector3 | A Vector3 with a value of 1 on the **Y** axis. |
zAxisVector3.zAxis: Vector3 | A Vector3 with a value of 1 on the **Z** axis. |
XVector3.X: number | X(左右)の値。The **X** coordinate of the Vector3. |
YVector3.Y: number | Y(上下)の値。The **Y** coordinate of the Vector3. |
ZVector3.Z: number | Z(前後)の値。The **Z** coordinate of the Vector3. |
MagnitudeVector3.Magnitude: number | ベクトルの長さ。2点の差のMagnitudeで、距離が求められます。The length of the Vector3. |
UnitVector3.Unit: Vector3 | 長さを1にしたベクトル(向きだけを表す)。A normalized copy of the Vector3 - one that has the same direction as the original but a magnitude of 1. |
メソッド(11)
| 名前と書き方 | 説明 |
|---|---|
AbsVector3:Abs(): Vector3 | Returns a new vector from the absolute values of the original's components. |
CeilVector3:Ceil(): Vector3 | Returns a new vector from the ceiling of the original's components. |
FloorVector3:Floor(): Vector3 | Returns a new vector from the floor of the original's components. |
SignVector3:Sign(): Vector3 | Returns a new vector from the sign (-1, 0, or 1) of the original's components. |
CrossVector3:Cross(other: Vector3): Vector3 | Returns the cross product of the two vectors. |
AngleVector3:Angle(other: Vector3, axis: Vector3): number | Returns the angle in radians between the two vectors. If you provide an axis, it determines the sign of the angle. |
DotVector3:Dot(other: Vector3): number | Returns a scalar dot product of the two vectors. |
FuzzyEqVector3:FuzzyEq(other: Vector3, epsilon: number): bool | Returns true if the difference between the squared magnitude of the two vectors is within epsilon. epsilon is scaled relative to the magnitude, rather than an absolute epsilon. |
LerpVector3:Lerp(goal: Vector3, alpha: number): Vector3 | Returns a Vector3 linearly interpolated between this Vector3 and the given goal by the given alpha. |
MaxVector3:Max(vector: Vector3): Vector3 | Returns a Vector3 with each component as the highest among the respective components of both provided Vector3 objects. |
MinVector3:Min(vector: Vector3): Vector3 | Returns a Vector3 with each component as the lowest among the respective components of both provided Vector3 objects. |
Vector3を使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(Vector3)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。