# Vector3（ロブロックス データ型）

> 3つの数（X・Y・Z）で、位置・大きさ・方向などを表すデータ型です。Vector3.new(0, 10, 0) のように作ります。

- URL：https://roblox.minecraft-okinawa.com/reference/datatypes/Vector3/
- 公式：https://create.roblox.com/docs/reference/engine/datatypes/Vector3

Xは左右、Yは上下、Zは前後の方向を表します。Vector3どうしは足し算・引き算ができ、Magnitudeで長さ（距離）を求められます。

## 使用例：位置と距離を扱う

（Script／置く場所：ServerScriptService）

```lua
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)
```

## コンストラクター

- `Vector3.new(x: number, y: number, z: number)`：X・Y・Zを指定してVector3を作ります。
- `Vector3.FromNormalId(normal: NormalId)`：Returns a new Vector3 in the given direction.
- `Vector3.FromAxis(axis: Axis)`：Returns a new Vector3 for the given axis.

## プロパティ

- `Vector3.zero: Vector3`：すべて0のベクトル。
- `Vector3.one: Vector3`：A Vector3 with a value of 1 on every axis.
- `Vector3.xAxis: Vector3`：A Vector3 with a value of 1 on the **X** axis.
- `Vector3.yAxis: Vector3`：A Vector3 with a value of 1 on the **Y** axis.
- `Vector3.zAxis: Vector3`：A Vector3 with a value of 1 on the **Z** axis.
- `Vector3.X: number`：X（左右）の値。
- `Vector3.Y: number`：Y（上下）の値。
- `Vector3.Z: number`：Z（前後）の値。
- `Vector3.Magnitude: number`：ベクトルの長さ。2点の差のMagnitudeで、距離が求められます。
- `Vector3.Unit: Vector3`：長さを1にしたベクトル（向きだけを表す）。

## メソッド

- `Vector3:Abs(): Vector3`：Returns a new vector from the absolute values of the original's components.
- `Vector3:Ceil(): Vector3`：Returns a new vector from the ceiling of the original's components.
- `Vector3:Floor(): Vector3`：Returns a new vector from the floor of the original's components.
- `Vector3:Sign(): Vector3`：Returns a new vector from the sign (-1, 0, or 1) of the original's components.
- `Vector3:Cross(other: Vector3): Vector3`：Returns the cross product of the two vectors.
- `Vector3: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.
- `Vector3:Dot(other: Vector3): number`：Returns a scalar dot product of the two vectors.
- `Vector3: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.
- `Vector3:Lerp(goal: Vector3, alpha: number): Vector3`：Returns a Vector3 linearly interpolated between this Vector3 and the given goal by the given alpha.
- `Vector3:Max(vector: Vector3): Vector3`：Returns a Vector3 with each component as the highest among the respective components of both provided Vector3 objects.
- `Vector3:Min(vector: Vector3): Vector3`：Returns a Vector3 with each component as the lowest among the respective components of both provided Vector3 objects.

英語の説明とメンバー一覧：Roblox Creator Documentation（CC BY 4.0）。日本語の解説はこのサイト独自のものです。

執筆：鈴木孝昌（現役プロジェクトマネージャー／プログラミング講師）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）