WorldRoot
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
このベースクラスは、3D 空間クエリとシミュレーションを処理するための API を提供します。たとえば、Workspace や、WorldModel など。
概要
プロパティ
Model から継承した プロパティインスタンスストリーミングを有効にしたエクスペリエンスの詳細レベルを設定します。
インスタンスストリーミングが有効になっているときに Models のモデルストリーミング動作を制御します。
Class.Model または nil が明示的に設定する定されていない場合のメイン部分。
モデルのピボットの周りにモデルをスケールするための編集者専用プロパティ。このプロパティを設定すると、スケールが Model/ScaleTo が呼び出されたように移動します。
Class.Model のピボットが 不 に設定されている場所を決定します。
方法
Class.BasePart のいずれかが他のパーツに触れている場合、Class.BasePart は true です。
指定した方向にブロックの形状を投影し、RaycastResult または BasePart セルにヒットすると、Terrain が返されます。
指定したボックスと重複する パーツの境界ボックス を返します。
境界ボックス を重複するパーツの配列を返します。
与えられたパーツと共有されているパーツのアレイを返します。
- IKMoveTo(part : BasePart,target : CFrame,translateStiffness : number,rotateStiffness : number,collisionsMode : Enum.IKCollisionsMode):void
部品を直接移動するのではなく、逆キネマティクスを使用して指定された場所に移動させ、ジョイント、制限、または衝突が参加することを確認して、部品が物理的に満足していることを確認します。
オリジン、方向、オプションの RaycastParams を使用して、レイを投射し、RaycastResult を返します。これは、資格のあるオブジェクトまたは地形がレイに接触する場合にのみ返す オプションの Datatype.RaycastParams を使用して、レイを投射し、1>Datatype.RaycastResult1> を返します。
- Spherecast(position : Vector3,radius : number,direction : Vector3,params : RaycastParams):RaycastResult?
指定された方向に球形を投げ、RaycastResultまたはBasePartのセルにヒットすると、Terrainを返します。
指定された時間増加とオプションのセットを含む、世界中のパーツのシミュレーションを進めます。Advances the simulation for parts in the world forward based on a specified time increment and an optional set of BaseParts .
このモデルを特定のプレイヤーのために持続化するように設定します。 Model.ModelStreamingMode は、 PersistentPerPlayer に設定されなければ、動作が追加された結果により変更されることはありません。
モデルのすべてのパーツが含まれているボリュームの説明を返します。
Class.BasePart|BaseParts が含まれる最小限のバウンドボックスのサイズを返します。Model 、Model.PrimaryPart が設定されている場合は、1>Class.BasePart|BaseParts1> が返されます。
このモデルオブジェクトが持続する Player すべてのオブジェクトを返します。このメソッドを Script から呼び出すか、LocalScript から呼び出すかによって動作は変わります。
モデルのキャノニカルスケールを返します。モデルの新規作成には、デフォルトで 1 が返されますが、Model/ScaleTo でスケールされると変更されます。
Class.Model.PrimaryPart|PrimaryPart を指定された位置に移動します。Class.Model.PrimaryPart が指定されていない場合は、モデルのルートパーツが使用されます。
このモデルは特定のプレイヤーのために再び持続しなくなります。 Model.ModelStreamingMode は、 PersistentPerPlayer に設定されて、結果として動作を変更するために変更された場合には持続しなくなります。
スケールファクターを設定し、すべての子孫インスタンスのサイズと場所を調整して、スケールファクターが 1 の場合、インスタンスのオリジナルサイズと場所に対するスケールファクターが相対的に変更されます。
Class.Model を Datatype.Vector3 のオフセットを保持しながら シフトすると、モデルのオリエンテーションを保持します。如果 他の Class.BasePart または Class.Terrain が新しい位置に既に存在する場合は、1> Class.Model は1>
Class.PVInstance のピボットを取得します。
Class.PVInstance とそのすべての子孫 PVInstances は、ピボットが指定の CFrame に移動します。
プロパティ
方法
ArePartsTouchingOthers
ArePartsTouchingOthers は、BasePart 以上のいずれかが他のパーツに触れている場合、またはその他のパーツに触れている場合、overlapIgnored である場合、0> タッチしている0> とみなされます。
パーツが提供されていない場合は、 false が返されます。
パラメータ
リストのパーツチェックを見ると、リストのパーツのいずれかがリストの外のパーツに触れているかどうかがわかります。
パーツが触れると考えられる前に無視されるパーツの重複サムネイル。
戻り値
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.
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 、サイズ、または方向入力が無効である場合、およびパスでエラーが発生します。
パラメータ
キャストブロックの形状の最初の位置と回転。
キャストブロックの形状のサイズは、スタッドです。最大サイズは 512 スタッドです。
シェープキャストの方向、および最大距離は、形状が移動できる最大距離を表す値です。最大距離は 1024 スタッドです。
戻り値
コードサンプル
Casts a block and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.
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
この関数は、BaseParts のテーブルを、必ずしもデフォルトプロパティのイベントを発動することなく、CFrames のテーブルに移動します。これにより、大きな数のパーツを非常に速く移動できます。また、個々のパーツの
3番目の引数を使用すると、移動オペレーションをさらに最適化できます。デフォルトでは、各パ
この関数を使用する必要がある場合は、コードのボトルネックが確信でない限り、個々のパーツと接続されたモデルの両方に注意してください。単に CFrame プロパティの個々のパーツと接続されたモデルを設定することは、大多数の場合、十分に速いです。
パラメータ
戻り値
GetPartBoundsInBox
WorldRoot:GetPartBoundsInBox() は、 境界ボックス を交差するボックスの量を記述するプレースを使用して、サイズを記述するボックスを返します。CFrame およびサイズを記述するボックスを返すサイズを返します。0>Datatype.Vector30> 。
強調されたように、この空間クエリメソッドは、実際のパーツのボリュームではなく、パーツの境界ボックスのボリュームを効率的に考慮します。これは、円筒、球、ユニオン、および MeshParts など、非ブロック形状の場合に特に重要です
このメソッドは、OverlapParamsオブジェクトを使用して、空間クエリの再利用可能な部分を説明します。たとえば、含有または含有なしのリスト、最大パーツ数をクエリ、BasePart.CanCollideを使用するか、クエリの<
パラメータ
指定されたボックスの音量の中心を指定します。
指定されたボックスの音量のサイズ。
空間クエリーパラメータの再利用可能な部分を含みます。
戻り値
空間クエリに一致する BaseParts の配列。
GetPartBoundsInRadius
Class.WorldRoot:GetPartBoundsInRadius() は、 サークルの境界 を使用して、Vector3 球の 0>Datatype.Vector30> と 3>Radius3> の間のパーツの WorldRoot:GetPartBoundsInRadius()6> を返します。
強調されたように、この空間クエリメソッドは、実際のパーツのボリュームではなく、パーツの境界ボックスのボリュームを効率的に考慮します。これは、円筒、球、ユニオン、および MeshParts など、非ブロック形状の場合に特に重要です
このメソッドは、OverlapParamsオブジェクトを使用して、空間クエリの再利用可能な部分を説明します。たとえば、含有または含有なしのリスト、最大パーツ数をクエリ、BasePart.CanCollideを使用するか、クエリの<
パラメータ
指定された球のボリュームの中心の場所。
指定された球のボリュームの範囲。
空間クエリーパラメータの再利用可能な部分を含みます。
戻り値
空間クエリに一致する BaseParts の配列。
GetPartsInPart
WorldRoot:GetPartsInPart() は、与えられたパーツと共有のスペースを持つパーツのアレイを返します (これは、WorldRoot のパーツと共有する必要があります)。このメソッドは BasePart:GetTouchingParts() の代わりに使用でき、一般的により良い選択です。
この空間クエリメソッドは、 正確なボリューム を使用して、WorldRoot:GetPartBoundsInBox()のパーツが実際に交差/接触することなく一致しないことを考慮しています。たとえ、より単純なボリュームでは、 Class.
このメソッドは、OverlapParamsオブジェクトを使用して、空間クエリの再利用可能な部分を説明します。たとえば、含有または含有なしのリスト、最大パーツ数をクエリ、BasePart.CanCollideを使用するか、クエリの<
パラメータ
ボリュームが他のパーツと比較される必要があるパーツ。
空間クエリーパラメータの再利用可能な部分を含みます。
戻り値
空間クエリに一致する BaseParts の配列。
IKMoveTo
この関数は、逆 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 は無視され、物理的な制限は、オブジェクトの位置で解決されます。
パラメータ
移動中のパーツ。
指定した部品を移動する場所。
物理解像度によって影響を受けるオブジェクトを指定することができます。
戻り値
Raycast
オリジン、方向、およびオプションの RaycastParams を使用して、レイをキャストします。如果、エリジブルな BasePart または Terrain
注: 向き向きベクトルの長さ (magnitude) は重要です。オブジェクト/地形の距離が長くなると、テストされなくなります。CFrame を使用してレイコンポーネントを作成している場合は、CFrame.LookVector を向
このメソッドは Ray 、但し、そのオリジンと方向コンポーネントは Ray.Origin 1> Datatype.Ray.Direction から借りることができます。
パラメータ
レイの起点。
射線の方向ベクトル。このベクトルの長さは、部品/地形の距離に応じてテストされないため、長さの影響を受けます。
レイキャストオペレーションのヒットエリビアリティを指定するオブジェクト。提供されていない場合は、すべてのパーツが検討され、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.
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
パラメータ
戻り値
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> プロパティは、
このメソッドは、無効な範囲または方向の入力をパスするとエラーをスローします。
パラメータ
キャスト球形の初期位置。
スタッドでスフィアシェイプの範囲。最大範囲は 256 スタッドです。
シェープキャストの方向、および最大距離は、形状が移動できる最大距離を表す値です。最大距離は 1024 スタッドです。
戻り値
コードサンプル
Casts a sphere and returns the first collision with a BasePart or Terrain. Prints the properties of the RaycastResult if a result was hit.
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
世界中のパーツのシミュレーションを進めるには、指定された時間
パラメータ
シミュレートする時間の量。この引数は正数でなければなりません。大きな値はこの関数の実行時間を上昇させます。
シミュレートするパーツのオプションの配列。このセットには、BasePart のインスタンスが含まれている必要があります。他のタイプは無視されます。
戻り値
コードサンプル
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.
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)