WorldRoot

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません

このベースクラスは、3D 空間クエリとシミュレーションを処理するための API を提供します。たとえば、Workspace や、WorldModel など。

概要

プロパティ

Model から継承した プロパティ
  • プラグインのセキュリティ
    並列読み取り

    インスタンスストリーミングを有効にしたエクスペリエンスの詳細レベルを設定します。

  • インスタンスストリーミングが有効になっているときに Models のモデルストリーミング動作を制御します。

  • 並列読み取り

    Class.Model または nil が明示的に設定する定されていない場合のメイン部分。

  • 複製されていません
    スクリプト作成できません
    並列読み取り

    モデルのピボットの周りにモデルをスケールするための編集者専用プロパティ。このプロパティを設定すると、スケールが Model/ScaleTo が呼び出されたように移動します。

  • 複製されていません
    並列読み取り

    Class.Model のピボットが に設定されている場所を決定します。

PVInstance から継承した プロパティ
  • 複製されていません
    スクリプト作成できません
    並列読み取り
  • 複製されていません
    スクリプト作成できません
    並列読み取り

方法

Model から継承した 方法
  • AddPersistentPlayer(playerInstance : Player):void

    このモデルを特定のプレイヤーのために持続化するように設定します。 Model.ModelStreamingMode は、 PersistentPerPlayer に設定されなければ、動作が追加された結果により変更されることはありません。

  • モデルのすべてのパーツが含まれているボリュームの説明を返します。

  • Class.BasePart|BaseParts が含まれる最小限のバウンドボックスのサイズを返します。ModelModel.PrimaryPart が設定されている場合は、1>Class.BasePart|BaseParts1> が返されます。

  • このモデルオブジェクトが持続する Player すべてのオブジェクトを返します。このメソッドを Script から呼び出すか、LocalScript から呼び出すかによって動作は変わります。

  • モデルのキャノニカルスケールを返します。モデルの新規作成には、デフォルトで 1 が返されますが、Model/ScaleTo でスケールされると変更されます。

  • MoveTo(position : Vector3):void

    Class.Model.PrimaryPart|PrimaryPart を指定された位置に移動します。Class.Model.PrimaryPart が指定されていない場合は、モデルのルートパーツが使用されます。

  • RemovePersistentPlayer(playerInstance : Player):void

    このモデルは特定のプレイヤーのために再び持続しなくなります。 Model.ModelStreamingMode は、 PersistentPerPlayer に設定されて、結果として動作を変更するために変更された場合には持続しなくなります。

  • ScaleTo(newScaleFactor : number):void

    スケールファクターを設定し、すべての子孫インスタンスのサイズと場所を調整して、スケールファクターが 1 の場合、インスタンスのオリジナルサイズと場所に対するスケールファクターが相対的に変更されます。

  • TranslateBy(delta : Vector3):void

    Class.Model を Datatype.Vector3 のオフセットを保持しながら シフトすると、モデルのオリエンテーションを保持します。如果 他の Class.BasePart または Class.Terrain が新しい位置に既に存在する場合は、1> Class.Model は1>

PVInstance から継承した 方法
  • 並列書き込み

    Class.PVInstance のピボットを取得します。

  • PivotTo(targetCFrame : CFrame):void

    Class.PVInstance とそのすべての子孫 PVInstances は、ピボットが指定の CFrame に移動します。

プロパティ

方法

ArePartsTouchingOthers

ArePartsTouchingOthers は、BasePart 以上のいずれかが他のパーツに触れている場合、またはその他のパーツに触れている場合、overlapIgnored である場合、0> タッチしている0> とみなされます。

パーツが提供されていない場合は、 false が返されます。

パラメータ

partList: Instances

リストのパーツチェックを見ると、リストのパーツのいずれかがリストの外のパーツに触れているかどうかがわかります。

overlapIgnored: number

パーツが触れると考えられる前に無視されるパーツの重複サムネイル。

既定値: 0.000199999995

戻り値

Class.Part|parts 中の partList のどれかに触れている場合、および、Class.Part|parts がパーツリストにある場合、その他のパーツに触れている場合は、1>Class.Part|parts1> が偽です。パーツリストにあるパーツがない場合は、4>Class.Part|parts4> が偽です。

コードサンプル

The code block below demonstrates how to use WorldRoot:ArePartsTouchingOthers() to check if parts in a list are touching any parts in the workspace not in the list.

First the script creates two square parts that overlap 1 stud, Part1 and Part2. Then, it prints the value returned by ArePartsTouchingOthers() when Part1 is passed in partList at three different overlap values: 0, 0.999, and 1. The first two times ArePartsTouchingOthers() is called return false because the overlap values are less than the distance that Part1 and Part2 overlap. The third call returns true because the overlap value is equal to the distance that the parts overlap.

Checking for Touching Parts

local part1 = Instance.new("Part")
part1.Name = "Part1"
part1.Anchored = true
part1.Transparency = 0.5
part1.Color = Color3.fromRGB(185, 100, 38)
part1.Size = Vector3.new(2, 2, 2)
part1.Position = Vector3.new(0, 4, 0)
part1.Parent = workspace
local part2 = Instance.new("Part")
part2.Name = "Part2"
part2.Anchored = true
part2.Transparency = 0.5
part2.Color = Color3.fromRGB(200, 10, 0)
part2.Size = Vector3.new(2, 2, 2)
part2.Position = Vector3.new(0, 5, 0)
part2.Parent = workspace
local partList = { part1 }
print(workspace:ArePartsTouchingOthers(partList, 0)) -- True
print(workspace:ArePartsTouchingOthers(partList, 0.999)) -- True
print(workspace:ArePartsTouchingOthers(partList, 1)) -- False

Blockcast

並列書き込み

指定された方向にブロックの形状を投げ、最初の衝突を BasePart または Terrain セルで最初に衝突します。これは、WorldRoot:Raycast() が直線的なレイを投げて衝突を見つける方法と同じですが、3D 形式ではなくレイを使用していま

Class.WorldRoot:GetPartsInPart() とは、BaseParts が形状を交差するときに、形状を交差する Class.WorldRoot:GetParts を検出しません。

ヒットが検出された場合、<a href="/reference/engine/datatypes">データ型</a>レイキャスト結果</a> が返され、ヒット情報が含まれます。<b>Datatype.RaycastResult.Distance|Distance</b> プロパティは、形状がヒットを見つけるために移動する距離を表示し、<c>Datatype.RaycastResult.Position|Position</c> プロパティは、

このメソッドは、CFrame 、サイズ、または方向入力が無効である場合、およびパスでエラーが発生します。

パラメータ

cframe: CFrame

キャストブロックの形状の最初の位置と回転。

size: Vector3

キャストブロックの形状のサイズは、スタッドです。最大サイズは 512 スタッドです。

direction: Vector3

シェープキャストの方向、および最大距離は、形状が移動できる最大距離を表す値です。最大距離は 1024 スタッドです。

既定値: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

シェープキャストオペレーションの結果、または nil を含む、 BasePart または Terrain セルがヒットされていない場合、エラーが発生しました。

コードサンプル

Casts a block and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.

Blockcasting

local Workspace = game:GetService("Workspace")
local function castBlock()
-- The initial position and rotation of the cast block shape
local originCFrame = CFrame.new(Vector3.new(0, 50, 0))
-- The size of the cast block shape
local size = Vector3.new(6, 3, 9)
-- The direction the block is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the cast
local distance = 50
-- Cast the block and create a visualization of it
local raycastResult = Workspace:Blockcast(originCFrame, size, direction * distance)
if raycastResult then
-- Print all properties of the RaycastResult if it exists
print(`Block intersected with: {raycastResult.Instance:GetFullName()}`)
print(`Intersection position: {raycastResult.Position}`)
print(`Distance between block's initial position and result: {raycastResult.Distance}`)
print(`The normal vector of the intersected face: {raycastResult.Normal}`)
print(`Material hit: {raycastResult.Material.Name}`)
else
print("Nothing was hit")
end
end
-- Continually cast a block every 2 seconds
while true do
castBlock()
task.wait(2)
end

BulkMoveTo

void

この関数は、BaseParts のテーブルを、必ずしもデフォルトプロパティのイベントを発動することなく、CFrames のテーブルに移動します。これにより、大きな数のパーツを非常に速く移動できます。また、個々のパーツの

3番目の引数を使用すると、移動オペレーションをさらに最適化できます。デフォルトでは、各パ

この関数を使用する必要がある場合は、コードのボトルネックが確信でない限り、個々のパーツと接続されたモデルの両方に注意してください。単に CFrame プロパティの個々のパーツと接続されたモデルを設定することは、大多数の場合、十分に速いです。

パラメータ

partList: Instances
cframeList: Array
既定値: "FireAllEvents"

戻り値

void

GetPartBoundsInBox

Instances
並列書き込み

WorldRoot:GetPartBoundsInBox() は、 境界ボックス を交差するボックスの量を記述するプレースを使用して、サイズを記述するボックスを返します。CFrame およびサイズを記述するボックスを返すサイズを返します。0>Datatype.Vector30> 。

強調されたように、この空間クエリメソッドは、実際のパーツのボリュームではなく、パーツの境界ボックスのボリュームを効率的に考慮します。これは、円筒、球、ユニオン、および MeshParts など、非ブロック形状の場合に特に重要です

このメソッドは、OverlapParamsオブジェクトを使用して、空間クエリの再利用可能な部分を説明します。たとえば、含有または含有なしのリスト、最大パーツ数をクエリ、BasePart.CanCollideを使用するか、クエリの<

パラメータ

cframe: CFrame

指定されたボックスの音量の中心を指定します。

size: Vector3

指定されたボックスの音量のサイズ。

overlapParams: OverlapParams

空間クエリーパラメータの再利用可能な部分を含みます。

既定値: "OverlapParams{MaxParts=0, Tolerance=0, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

Instances

空間クエリに一致する BaseParts の配列。

GetPartBoundsInRadius

Instances
並列書き込み

Class.WorldRoot:GetPartBoundsInRadius() は、 サークルの境界 を使用して、Vector3 球の 0>Datatype.Vector30> と 3>Radius3> の間のパーツの WorldRoot:GetPartBoundsInRadius()6> を返します。

強調されたように、この空間クエリメソッドは、実際のパーツのボリュームではなく、パーツの境界ボックスのボリュームを効率的に考慮します。これは、円筒、球、ユニオン、および MeshParts など、非ブロック形状の場合に特に重要です

このメソッドは、OverlapParamsオブジェクトを使用して、空間クエリの再利用可能な部分を説明します。たとえば、含有または含有なしのリスト、最大パーツ数をクエリ、BasePart.CanCollideを使用するか、クエリの<

パラメータ

position: Vector3

指定された球のボリュームの中心の場所。

radius: number

指定された球のボリュームの範囲。

overlapParams: OverlapParams

空間クエリーパラメータの再利用可能な部分を含みます。

既定値: "OverlapParams{MaxParts=0, Tolerance=0, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

Instances

空間クエリに一致する BaseParts の配列。

GetPartsInPart

Instances
並列書き込み

WorldRoot:GetPartsInPart() は、与えられたパーツと共有のスペースを持つパーツのアレイを返します (これは、WorldRoot のパーツと共有する必要があります)。このメソッドは BasePart:GetTouchingParts() の代わりに使用でき、一般的により良い選択です。

この空間クエリメソッドは、 正確なボリューム を使用して、WorldRoot:GetPartBoundsInBox()のパーツが実際に交差/接触することなく一致しないことを考慮しています。たとえ、より単純なボリュームでは、 Class.

このメソッドは、OverlapParamsオブジェクトを使用して、空間クエリの再利用可能な部分を説明します。たとえば、含有または含有なしのリスト、最大パーツ数をクエリ、BasePart.CanCollideを使用するか、クエリの<

パラメータ

part: BasePart

ボリュームが他のパーツと比較される必要があるパーツ。

overlapParams: OverlapParams

空間クエリーパラメータの再利用可能な部分を含みます。

既定値: "OverlapParams{MaxParts=0, Tolerance=0, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

Instances

空間クエリに一致する BaseParts の配列。

IKMoveTo

void
プラグインのセキュリティ

この関数は、逆 kinematics を介して指定された部分を指定された場所に移動するため、ジョイントを確認し、constraints または衝突が部分に参加することを確認するために、直接そこに移動することはありません。現在、この関数は Studio でのみ Class

硬度を翻訳する は、0から1の数字で、パーツの位置をターゲットの CFrame の位置パーツとどのくらい一致させるかを指定します。 硬度を回転する は、0から1の数字で、パーツの回転をターゲットの CFrame の回転部分にどのくらい一致させるかを指定します。

たとえば:

  • 如果 translation stiffness と rotate stiffness が 1 で同等である場合、部品は、その上に存在する物理的な制限にかかわらず、ターゲットの CFrame に正確に移動します。
  • 硬度と回転硬度が 0.5 で同等である場合、パーツは完全にターゲットの CFrame に移動しようとしますが、物理的な制限により道を離れる可能性があります。
  • If translate stiffness and rotate stiffness が 0 で同等である場合、ターゲットの CFrame は無視され、物理的な制限は、オブジェクトの位置で解決されます。

パラメータ

part: BasePart

移動中のパーツ。

target: CFrame

指定した部品を移動する場所。

translateStiffness: number

0 から 1 の間の数値で、パーツの位置をターゲットの位置のパーツとの一致度を指定します。CFrame

既定値: 0.5
rotateStiffness: number

0 から 1 の間の数値で、パーツの回転をターゲットの回転部分に合うようにどれくらい攻撃的にマッチするかを指定します CFrame

既定値: 0.5
collisionsMode: Enum.IKCollisionsMode

物理解像度によって影響を受けるオブジェクトを指定することができます。

既定値: "OtherMechanismsAnchored"

戻り値

void
並列書き込み

オリジン、方向、およびオプションの RaycastParams を使用して、レイをキャストします。如果、エリジブルな BasePart または Terrain

注: 向き向きベクトルの長さ (magnitude) は重要です。オブジェクト/地形の距離が長くなると、テストされなくなります。CFrame を使用してレイコンポーネントを作成している場合は、CFrame.LookVector を向

このメソッドは Ray 、但し、そのオリジンと方向コンポーネントは Ray.Origin 1> Datatype.Ray.Direction から借りることができます。

パラメータ

origin: Vector3

レイの起点。

direction: Vector3

射線の方向ベクトル。このベクトルの長さは、部品/地形の距離に応じてテストされないため、長さの影響を受けます。

raycastParams: RaycastParams

レイキャストオペレーションのヒットエリビアリティを指定するオブジェクト。提供されていない場合は、すべてのパーツが検討され、Terrain 水が無視されます。

既定値: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

レイキャストオペレーションの結果、または nil を含む、 BasePart または Terrain のセルがヒットされていない場合の結果を含みます。

コードサンプル

Casts a ray and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.

Raycasting

local Workspace = game:GetService("Workspace")
local function castRay()
-- The origin point of the ray
local originPosition = Vector3.new(0, 50, 0)
-- The direction the ray is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the ray
local distance = 50
-- Cast the ray and create a visualization of it
local raycastResult = Workspace:Raycast(originPosition, direction * distance)
if raycastResult then
-- Print all properties of the RaycastResult if it exists
print(`Ray intersected with: {raycastResult.Instance:GetFullName()}`)
print(`Intersection position: {raycastResult.Position}`)
print(`Distance between ray origin and result: {raycastResult.Distance}`)
print(`The normal vector of the intersected face: {raycastResult.Normal}`)
print(`Material hit: {raycastResult.Material.Name}`)
else
print("Nothing was hit")
end
end
-- Continually cast a ray every 2 seconds
while true do
castRay()
task.wait(2)
end

Shapecast

パラメータ

part: BasePart
direction: Vector3
既定値: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

Spherecast

並列書き込み

指定された方向に球形を投げ、最初の衝突を BasePart または Terrain セルで返します。これは、WorldRoot:Raycast() が直線的なレイを投げて衝突を見つける方法と同じですが、3D 形式ではなくレイを使用しています。

Class.WorldRoot:GetPartsInPart() とは、BaseParts が形状を交差するときに、形状を交差する Class.WorldRoot:GetParts を検出しません。

ヒットが検出された場合、<a href="/reference/engine/datatypes">データ型</a>レイキャスト結果</a> が返され、ヒット情報が含まれます。<b>Datatype.RaycastResult.Distance|Distance</b> プロパティは、形状がヒットを見つけるために移動する距離を表示し、<c>Datatype.RaycastResult.Position|Position</c> プロパティは、

このメソッドは、無効な範囲または方向の入力をパスするとエラーをスローします。

パラメータ

position: Vector3

キャスト球形の初期位置。

radius: number

スタッドでスフィアシェイプの範囲。最大範囲は 256 スタッドです。

direction: Vector3

シェープキャストの方向、および最大距離は、形状が移動できる最大距離を表す値です。最大距離は 1024 スタッドです。

既定値: "RaycastParams{IgnoreWater=false, BruteForceAllSlow=false, RespectCanCollide=false, CollisionGroup=Default, FilterDescendantsInstances={}}"

戻り値

シェープキャストオペレーションの結果、または nil を含む、 BasePart または Terrain セルがヒットされていない場合、エラーが発生しました。

コードサンプル

Casts a sphere and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.

Spherecasting

local Workspace = game:GetService("Workspace")
local function castSphere()
-- The initial position of the cast spherical shape
local originPosition = Vector3.new(0, 50, 0)
-- The radius of the cast spherical shape in studs
local radius = 10
-- The direction the sphere is cast in
local direction = -Vector3.yAxis
-- The maximum distance of the cast
local distance = 50
-- Cast the sphere and create a visualization of it
local raycastResult = Workspace:Spherecast(originPosition, radius, direction * distance)
if raycastResult then
-- Print all properties of the RaycastResult if it exists
print(`Sphere intersected with: {raycastResult.Instance:GetFullName()}`)
print(`Intersection position: {raycastResult.Position}`)
print(`Distance between sphere's initial position and result: {raycastResult.Distance}`)
print(`The normal vector of the intersected face: {raycastResult.Normal}`)
print(`Material hit: {raycastResult.Material.Name}`)
else
print("Nothing was hit")
end
end
-- Continually cast a sphere every 2 seconds
while true do
castSphere()
task.wait(2)
end

StepPhysics

void
プラグインのセキュリティ

世界中のパーツのシミュレーションを進めるには、指定された時間

パラメータ

dt: number

シミュレートする時間の量。この引数は正数でなければなりません。大きな値はこの関数の実行時間を上昇させます。

parts: Instances

シミュレートするパーツのオプションの配列。このセットには、BasePart のインスタンスが含まれている必要があります。他のタイプは無視されます。

既定値: "{}"

戻り値

void

コードサンプル

Simulates the parts in the workspace for a fixed period of time by calling the StepPhysics function once per frame until a specified time has elaspsed.

StepPhysics

local RunService = game:GetService("RunService")
-- Optional array of parts to simulate; otherwise all parts will be simulated
local partsToSimulate = {
workspace.Part
}
local function simulateParts(duration)
local time = 0.0
local stepJob
stepJob = RunService.RenderStepped:Connect(function(dt)
if time + dt > duration then
dt = duration - time
end
workspace:StepPhysics(dt, partsToSimulate)
time = time + dt
if time >= duration then
stepJob:Disconnect()
end
end)
end
-- Simulate workspace parts for 5 seconds, stepping the parts once per frame
simulateParts(5.0)

イベント