BasePart
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
BasePart は、Workspace でレンダリングされ、物理的にシミュレートされている世界のオブジェクトの抽象ベースクラスです。BasePart には複数の実装があり、最も一般的なのは Part と MeshPart です。他には、WedgePart、SpawnLocation、およびシングルトンオブジェクト Terrain が含まれます。一般的に、ドキュメントが「パーツ」を参照すると、ほとんどの BasePart 実装は機能し、単に Part ではありません。
For information on how BaseParts はシミュレーションされた剛体にグループ化される方法については、アセンブリ を参照してください。
インタラクトする多くの異なるオブジェクトがあります BasePart (Terrain 以外)、包括:
- Attachments は、BasePart に追加して、パーツに関連する CFrames を指定できます。これらは、機械的な制限 および 移動制限 で説明されたように、物理的な Constraint が頻繁に使用します。
- オブジェクトは、親になった のボリュームで一貫して粒子を放出します。「パーティクルエミッター」を参照してください。
概要
プロパティ
パーツが物理的に移動不可能かどうかを決定します。
部品の組み立ての角速度。
ワールドスペースでのパーツのアセンブリの質量の中心。
部品の組み立ての線速度。
パーツのアセンブリの総質量。
アセンブリの根部に対する参照。
パーツがオーディオシミュレーションと物理的に相互作用するかどうかを決定します。照明のための CastShadow と同様です。
部品の後面の表面タイプを決定します。
部品の底面の表面タイプを決定します。
部品の色を決定します。
世界の BasePart の位置と方向を決定します。
パーツが他のパーツと衝突できるかどうかを決定します。
パーツが空間クエリ操作で考慮されるかどうかを決定します。
Touched および TouchEnded イベントがパーツに発射するかどうかを決定します。
パーツがシャドウをキャストするかどうかを決定します。
部品の質量の中心が位置する世界の位置を説明します。
パーツの衝突グループの名前を記述します。
部品の色を決定します。
部品の現在の物理プロパティを示します。
部品の複数の物理的特性を決定します。
部品やアセンブリの空力を有効化または無効化するのに使用します。
物理エンジンによって見られる BasePart の実際のサイズ。
部品の前面の表面タイプを決定します。
部品の左面の表面タイプを決定します。
ローカルクライアントにしか表示されない BasePart.Transparency の乗数を決定します。
スタジオでパーツが選択可能かどうかを決定します。
部品の質量、密度とボリュームの積を記述します。
パーツが剛ボディの総質量または粘性に貢献するかどうかを決定します。
部品のテクスチャとデフォルトの物理プロパティを決定します。
名前の MaterialVariant 。
世界でのパーツの回転を説明します。
パーツのピボットのオフセットを、CFrame から指定します。
世界のパーツの位置を記述します。
最後の物理アップデート以来の時間。
パーツが天空ボックスをどの程度反映するかを決定します。
Resize() メソッドで許可される最小サイズ変更を説明します。
パーツがサイズ変更できる顔を説明します。
部品の右面の表面タイプを決定します。
アセンブリのルート部分を決定する主なルール。
3軸のためのパーツの回転度です。
部品の寸法 (長さ、幅、高さ) を決定します。
部品の上面のタイプを決定します。
パーツがどの程度透明に見えるかを決定します (パーツの不透明度の逆)。
方法
アングルパルスをアセンブリに適用します。
アセンブリの center of mass にアインプルスを適用します。
指定された位置にアセンブリにインパルスを適用します。
パーツが互いに衝突できるかどうかを返します。
パーツのネットワーク所有権を設定できるかどうかをチェックします。
剛性ジョイントでオブジェクトに接続されたパーツのテーブルを返します。
このパーツに接続されているすべてのジョイントまたは制限を返す。
Mass プロパティの値を返します。
この部分のネットワーク所有者である現在のプレイヤーを返すか、nil は、サーバーの場合。
ゲームエンジンが自動的にこの部分のネットワーク所有者を決定する場合、真を返します。
パーツのアセンブリのベース部分を返します。
このパーツと交差するすべての BasePart.CanCollide 真のパーツの表を返します。
このパーツに対する位置に関連して、部品の組み立ての線速度を返します。
オブジェクトがそれを保持するパーツに接続されている場合 (例: Anchored パーツ) は真を返し、そうでない場合は false を返します。
Studio のサイズ変更ツールを使用するのと同じように、オブジェクトのサイズを変更します。
指定されたプレイヤーをこのネットワークの所有者とすべての接続部品の所有者とします。
ゲームエンジンが動的に、パーツの物理を処理する人 (クライアントの 1 人またはサーバー) を決定できます。
- IntersectAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
パーツとその他のパーツの重複する幾何学から新しい IntersectOperation を作成し、指定された配列に追加します。
- SubtractAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
パーツから新しい UnionOperation を作成し、指定されたアレイに含まれるパーツによって占有される幾何学を除きます。
- UnionAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
パーツから新しい UnionOperation を作成し、指定された配列内のパーツによって占有された幾何学を加えます。
PVInstance のピボットを取得します。
変換する PVInstance とすべての子孫 PVInstances を通じて、ピボットが現在指定された CFrame に位置します。
イベント
物理的な移動の結果、パーツが他のパーツに触れなくなると発火します。
物理的な移動の結果、パーツが他のパーツに触れると発火します。
プロパティ
Anchored
Anchored プロパティは、パーツが物理的に移動できないかどうかを決定します。有効にすると、部品は重力、他の部品の衝突、他の部品の重複、その他の物理関連の原因により、位置が変更されることはありません。結果として、2つのアンカー部品はお互いに Touched イベントを発射しないことになります。
アンカー付きのパーツは、CFrame または Position を変更することで引き続き移動でき、依然としてゼロ以上の AssemblyLinearVelocity と AssemblyAngularVelocity を持つ可能性があります。
最後に、未固定のパーツが Weld のようなオブジェクトを介して固定パーツに接続された場合、それも固定化されます。そのようなジョイントが破損すると、パーツが物理に再び影響を受ける可能性があります。詳細については、アセンブリ を参照してください。
ネットワーク所有権は、アンカーされたパーツに設定できません。パーツのアンカー状態がサーバーで変更されると、そのパーツのネットワーク所有権が影響を受けます。
コードサンプル
This code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).
local part = script.Parent
-- Create a ClickDetector so we can tell when the part is clicked
local cd = Instance.new("ClickDetector", part)
-- This function updates how the part looks based on its Anchored state
local function updateVisuals()
if part.Anchored then
-- When the part is anchored...
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.DiamondPlate
else
-- When the part is unanchored...
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Wood
end
end
local function onToggle()
-- Toggle the anchored property
part.Anchored = not part.Anchored
-- Update visual state of the brick
updateVisuals()
end
-- Update, then start listening for clicks
updateVisuals()
cd.MouseClick:Connect(onToggle)
AssemblyAngularVelocity
このパーツの組み立ての角速度ベクトル。秒ごとのオリエンテーションの変更率です。
アングル速度は、アセンブリの各ポイントで同じです。
直接速度を設定すると、現実的でない動作になり得ます。Torque または AngularVelocity 制約を使用するか、速度の即時変更を望む場合は ApplyAngularImpulse() を使用します。
パーツがサーバーに 所有されている場合 、このプロパティはサーバーから 変更する必要があります ( または で設定された からではない).パーツが 自動 所有権を通じてクライアントに所有されている場合、このプロパティは、クライアントスクリプトから または サーバースクリプトから変更できます;サーバーが所有するパーツのクライアントスクリプトで変更すると、効果はありません。
AssemblyCenterOfMass
アセンブリ内のすべてのパーツの Mass と Position を通じて計算された位置
アセンブリに固定部分がある場合、その部分の質量センターはアセンブリの質量センターになり、アセンブリに無限の質量があります。
質量の中心を知ることで、アセンブリの安定性を維持することができます。質量の中心に適用された力は、角度加速を引き起こさない、線形のみです。質量の低いアセンブリは、重力の効果の下で立ったままの時間がより良くなります。
AssemblyLinearVelocity
このパーツの組み立ての線速度ベクトル。それは、スタッド毎秒の位置変更率です。AssemblyCenterOfMass です。
アセンブリの質量の中心以外の速度を知りたい場合は、GetVelocityAtPosition() を使用します。
直接速度を設定すると、現実的でない動作になり得ます。VectorForce 制約を使用するか、速度の即時変更を希望する場合は ApplyImpulse() を使用します。
パーツがサーバーに 所有されている場合 、このプロパティはサーバーから 変更する必要があります ( または で設定された からではない).パーツが 自動 所有権を通じてクライアントに所有されている場合、このプロパティは、クライアントスクリプトから または サーバースクリプトから変更できます;サーバーが所有するパーツのクライアントスクリプトで変更すると、効果はありません。
AssemblyMass
このパーツのアセンブリ全体の BaseParts の質量の合計。パーツが Massless であり、アセンブリのルートパーツではないものは、AssemblyMass に貢献しません。
アセンブリに固定部分がある場合、アセンブリのマスは無限と考えられます。大きな差があるアンカーなしアセンブリの間の制限や他の物理的な相互作用は、不安定性を引き起こす可能性があります。
AssemblyRootPart
このプロパティは、アセンブリのルートパーツを表現するために自動的に選択された BasePart を示します。開発者が GetRootPart() を呼び出すと返されるのと同じパーツです。
ルートパーツは、アセンブリ内のパーツの RootPriority を変更することで変更できます。
すべて同じ AssemblyRootPart を共有するパーツは、同じアセンブリにあります。
ルートパーツに関する詳細情報は、アセンブリ を参照してください。
AudioCanCollide
AudioCanCollide は、パーツが照明のための CastShadow と同様に、オーディオシミュレーションと物理的に相互作用するかどうかを決めます。
無効にすると、オーディオがパーツを通過し、遮断されたり反射されたりしません。
BackSurface
BackSurface プロパティは、パーツの正の Z 方向に使用される表面の種類を決定します。2つのパーツの面が互いに隣り合うと、間にジョイントが生成される可能性があります。
BottomSurface
BottomSurface プロパティは、パーツの負の Y 方向に使用される表面の種類を決定します。2つのパーツの面が互いに隣り合うと、間にジョイントが生成される可能性があります。
BrickColor
このプロパティは、パーツの色を決定します。パーツに Material がある場合、これは材料テクスチャをレンダリングするときに使用される色を決定します。色により多くの制御を行うには、Color プロパティを使用でき、このプロパティは最も近いBrickColorを使用します。
パーツの他の視覚的プロパティは、Transparency および Reflectance によって決まります。
CFrame
CFrame プロパティは、世界の中の BasePart の位置と方向を決定します。幾何学上の任意の参照場所として機能しますが、ExtentsCFrame は物理センターの実際の CFrame を表します。
パーツに CFrame を設定すると、他の参加パーツもパーツに対して移動しますが、プレイヤーのキャラクターをテレポートするような、全モデルを移動するために PVInstance:PivotTo() を使用することをお勧めします。
設定 とは異なり、設定 は常にパーツを正確に指定された に移動します;言い換えれば、パーツの重複チェックは行われず、物理ソリューションは、両方のパーツが でない限り、重複を解決しようとします。
パーツの CFrame に対する位置を追跡するために、Attachment が役立つかもしれません。
コードサンプル
This code sample demonstrates setting a part's CFrame in many different ways. It showcases how to create and compose CFrame values. It references a sibling part called "OtherPart" for demonstrating relative positioning.
local part = script.Parent:WaitForChild("Part")
local otherPart = script.Parent:WaitForChild("OtherPart")
-- Reset the part's CFrame to (0, 0, 0) with no rotation.
-- This is sometimes called the "identity" CFrame
part.CFrame = CFrame.new()
-- Set to a specific position (X, Y, Z)
part.CFrame = CFrame.new(0, 25, 10)
-- Same as above, but use a Vector3 instead
local point = Vector3.new(0, 25, 10)
part.CFrame = CFrame.new(point)
-- Set the part's CFrame to be at one point, looking at another
local lookAtPoint = Vector3.new(0, 20, 15)
part.CFrame = CFrame.lookAt(point, lookAtPoint)
-- Rotate the part's CFrame by pi/2 radians on local X axis
part.CFrame = part.CFrame * CFrame.Angles(math.pi / 2, 0, 0)
-- Rotate the part's CFrame by 45 degrees on local Y axis
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(45), 0)
-- Rotate the part's CFrame by 180 degrees on global Z axis (note the order!)
part.CFrame = CFrame.Angles(0, 0, math.pi) * part.CFrame -- Pi radians is equal to 180 degrees
-- Composing two CFrames is done using * (the multiplication operator)
part.CFrame = CFrame.new(2, 3, 4) * CFrame.new(4, 5, 6) --> equal to CFrame.new(6, 8, 10)
-- Unlike algebraic multiplication, CFrame composition is NOT communitative: a * b is not necessarily b * a!
-- Imagine * as an ORDERED series of actions. For example, the following lines produce different CFrames:
-- 1) Slide the part 5 units on X.
-- 2) Rotate the part 45 degrees around its Y axis.
part.CFrame = CFrame.new(5, 0, 0) * CFrame.Angles(0, math.rad(45), 0)
-- 1) Rotate the part 45 degrees around its Y axis.
-- 2) Slide the part 5 units on X.
part.CFrame = CFrame.Angles(0, math.rad(45), 0) * CFrame.new(5, 0, 0)
-- There is no "CFrame division", but instead simply "doing the inverse operation".
part.CFrame = CFrame.new(4, 5, 6) * CFrame.new(4, 5, 6):Inverse() --> is equal to CFrame.new(0, 0, 0)
part.CFrame = CFrame.Angles(0, 0, math.pi) * CFrame.Angles(0, 0, math.pi):Inverse() --> equal to CFrame.Angles(0, 0, 0)
-- Position a part relative to another (in this case, put our part on top of otherPart)
part.CFrame = otherPart.CFrame * CFrame.new(0, part.Size.Y / 2 + otherPart.Size.Y / 2, 0)
CanCollide
CanCollide は、パーツが他のパーツと物理的に相互作用するかどうかを決定します。無効にすると、他の部分が中断されずにパーツを通過できます。 装飾 に使用されるパーツは、通常、物理エンジンで考慮する必要がないため、CanCollide が無効になっています。
パーツが Anchored ではなく、CanCollide が無効になっている場合、世界から落ちて最終的に Workspace.FallenPartsDestroyHeight によって破壊される可能性があります。
When CanCollide が無効になっていると、パーツはまだ Touched イベントを発射する可能性があります (他のパーツも含まれます)。これを無効にするには、CanTouch です。
衝突に関する詳細は、衝突 を参照してください。
コードサンプル
This code sample shows how a part can fade away when touched by a Humanoid then reappear a moment after to create a passable door.
-- Paste into a Script inside a tall part
local part = script.Parent
local OPEN_TIME = 1
-- Can the door be opened at the moment?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("Black")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("Bright blue")
end
local function onTouch(otherPart)
-- If the door was already open, do nothing
if debounce then
print("D")
return
end
-- Check if touched by a Humanoid
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("not human")
return
end
-- Perform the door opening sequence
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()
CanQuery
このプロパティは、パーツが GetPartBoundsInBox または Raycast のような空間クエリ操作で考慮されるかどうかを決定します。Note that が有効になるためには、 が有効になる必要があり、空間クエリ機能には のパーツが含まれることはありません。
このプロパティ以上に、スペーシャルクエリ機能を呼び出すときに OverlapParams または RaycastParams オブジェクトを使用して、指定のパーツの子孫を除外することもできます。
CanTouch
このプロパティは、Touched および TouchEnded イベントがパーツに発射するかどうかを決定します。If 、他のタッチ部品もタッチイベントが発動するために に設定する必要があります。If false 、タッチイベントはパーツに設定できません、それを行おうとするとエラーが発生します。同様に、タッチイベントが接続された後、プロパティが false に設定されると、イベントは切断され、TouchTransmitter が削除されます。
この衝突ロジックは、衝突グループ を尊重するように設定でき、Workspace.TouchesUseCollisionGroups を通じて設定できます。If true 、非衝突グループのパーツは、両方の衝突 と タッチイベントを無視し、このプロパティを無効にします。
性能
これらのパーツは、 と が両方設定されているため、パーツ間の衝突を計算する必要がありません。小さなパフォーマンスの向上があります。しかし、Raycasts および OverlapParams クエリによって依然として攻撃を受ける可能性があります。
CastShadow
パーツがシャドウをキャストするかどうかを決定します。このプロパティを指定されたパーツに無効にすると、そのパーツに投影されたシャドウに視覚的なアーティファクトが生じる可能性があります。
このプロパティはパフォーマンスの向上を目的として設計されていませんが、複雑なシーンでは、特定の部分を戦略的に無履行にすることでパフォーマンスが向上する可能性があります。視覚的なアーティファクトの可能性により、ほとんどの状況で全部に有効にすることをお勧めします。
CenterOfMass
CenterOfMass プロパティは、パーツの質量の中心の位置を ローカル に説明します。これが単一パーツアセンブリの場合、これは世界空間からローカルに変換された AssemblyCenterOfMass です。単純な Parts では、質量の中心は常に (0, 0, 0) ですが、WedgePart または MeshPart で変わる可能性があります。
CollisionGroup
CollisionGroup プロパティは、パーツの衝突グループの名前を記述します (最大 100 文字)。パーツは、名前が "Default" のデフォルトグループで開始します。この値は空ではありません。
このプロパティ自体は非リプリケーションですが、エンジンはバックワード互換の問題を解決するために、別のプライベートプロパティを通じて値を内部的にリプリケートします。
コードサンプル
This example demonstrates one basic use of collision groups. It assigns BallPart to "CollisionGroupBall" and DoorPart to "CollisionGroupDoor", then makes the two groups non-collidable using PhysicsService:CollisionGroupSetCollidable().
local PhysicsService = game:GetService("PhysicsService")
local collisionGroupBall = "CollisionGroupBall"
local collisionGroupDoor = "CollisionGroupDoor"
-- Register collision groups
PhysicsService:RegisterCollisionGroup(collisionGroupBall)
PhysicsService:RegisterCollisionGroup(collisionGroupDoor)
-- Assign parts to collision groups
script.Parent.BallPart.CollisionGroup = collisionGroupBall
script.Parent.DoorPart.CollisionGroup = collisionGroupDoor
-- Set groups as non-collidable with each other and check the result
PhysicsService:CollisionGroupSetCollidable(collisionGroupBall, collisionGroupDoor, false)
print(PhysicsService:CollisionGroupsAreCollidable(collisionGroupBall, collisionGroupDoor)) --> false
Color
Color プロパティは、パーツの色を決定します。パーツに Material がある場合、これは材料テクスチャをレンダリングするときに使用される色を決定します。
このプロパティが設定する定されている場合、BrickColor は、この Color 値に最も近い一致を使用します。
パーツの他の視覚的プロパティは、Transparency および Reflectance によって決まります。
コードサンプル
This code sample colors a player's entire character based on how much health they have. It generates a color based on their max health, then sets the color properties of objects within their character, removing any extra objects.
-- Paste into a Script within StarterCharacterScripts
-- Then play the game, and fiddle with your character's health
local char = script.Parent
local human = char.Humanoid
local colorHealthy = Color3.new(0.4, 1, 0.2)
local colorUnhealthy = Color3.new(1, 0.4, 0.2)
local function setColor(color)
for _, child in pairs(char:GetChildren()) do
if child:IsA("BasePart") then
child.Color = color
while child:FindFirstChildOfClass("Decal") do
child:FindFirstChildOfClass("Decal"):Destroy()
end
elseif child:IsA("Accessory") then
child.Handle.Color = color
local mesh = child.Handle:FindFirstChildOfClass("SpecialMesh")
if mesh then
mesh.TextureId = ""
end
elseif child:IsA("Shirt") or child:IsA("Pants") then
child:Destroy()
end
end
end
local function update()
local percentage = human.Health / human.MaxHealth
-- Create a color by tweening based on the percentage of your health
-- The color goes from colorHealthy (100%) ----- > colorUnhealthy (0%)
local color = Color3.new(
colorHealthy.R * percentage + colorUnhealthy.r * (1 - percentage),
colorHealthy.G * percentage + colorUnhealthy.g * (1 - percentage),
colorHealthy.B * percentage + colorUnhealthy.b * (1 - percentage)
)
setColor(color)
end
update()
human.HealthChanged:Connect(update)
CurrentPhysicalProperties
CurrentPhysicalProperties は、パーツの現在の物理的プロパティを示します。パーツごとの物理プロパティのカスタム値、カスタム素材、およびマテリアルオーバーライドを設定できます。Roblox エンジンは、パーツの有効な物理プロパティを決定するとき、より粒度の高い定義を優先します。次のリストの値は、最も優先度の高い順に並んでいます:
- 部品のカスタム物理プロパティ
- パーツのカスタム物質のカスタム物理プロパティ
- 部品の材料のオーバーライドのカスタム物理プロパティ
- パーツの素材のデフォルトの物理プロパティ
CustomPhysicalProperties
CustomPhysicalProperties では、密度、摩擦、弾性などのパーツの物理的な側面をカスタマイズできます。
有効にすると、このプロパティでこれらの物理プロパティを構成できます。無効にすると、これらの物理プロパティはパーツの Material によって決定されます。
コードサンプル
This code sample demonstrates how to set the CustomPhysicalProperties property of a part.
local part = script.Parent
-- This will make the part light and bouncy!
local DENSITY = 0.3
local FRICTION = 0.1
local ELASTICITY = 1
local FRICTION_WEIGHT = 1
local ELASTICITY_WEIGHT = 1
local physProperties = PhysicalProperties.new(DENSITY, FRICTION, ELASTICITY, FRICTION_WEIGHT, ELASTICITY_WEIGHT)
part.CustomPhysicalProperties = physProperties
EnableFluidForces
When true , and when Workspace.FluidForces が有効になっていると、物理エンジンがこの BasePart に空気力学の力を計算します。
FrontSurface
FrontSurface プロパティは、パーツの負の Z 方向に使用される表面の種類を決定します。2つのパーツの面が互いに隣り合うと、間にジョイントが生成される可能性があります。
LeftSurface
LeftSurface プロパティは、パーツの負の X 方向に使用される表面の種類を決定します。2つのパーツの面が互いに隣り合うと、間にジョイントが生成される可能性があります。
LocalTransparencyModifier
LocalTransparencyModifier プロパティは、ローカルクライアントにしか表示されない Transparency 乗数です。クライアントからサーバーにレプリケートしないため、プレイヤーがファーストパーソンモードでキャラクターの身体部分を見えないときなど、パーツが特定のクライアントにレンダリングされない場合に便利です。
このプロパティは、次の式でローカルパーツの透明度を変更し、結果の値は 0 と 1 の間に収まります。
1 - (( 1 - Transparency ) × ( 1 - LocalTransparencyModifier ))
<th><code>ローカル透明性修正者</code></th><th>サーバー側</th><th>クライアント側</th></tr></thead><tbody><tr><td><code>0.5</code></td><td><code>0</code></td><td><code>0.5</code></td><td><code>0.5</code></td></tr><tr><td><code>0.5</code></td><td><code>0.25</code></td><td><code>0.5</code></td><td><code>0.625</code></td></tr><tr><td><code>0.5</code></td><td><code>0.5</code></td><td><code>0.5</code></td><td><code>0.75</code></td></tr><tr><td><code>0.5</code></td><td><code>0.75</code></td><td><code>0.5</code></td><td><code>0.875</code></td></tr><tr><td><code>0.5</code></td><td><code>1</code></td><td><code>0.5</code></td><td><code>1</code></td></tr></tbody>
Locked
プロパティは、パーツ (またはその中に含まれている) が Studio でクリックして選択できるかどうかを決定します。このプロパティは、現在編集されていない環境モデル内のパーツで最もよく有効になっています。
コードサンプル
This code sample uses the concept of recursion to unlock all parts that are a descendant of a model.
-- Paste into a Script within a Model you want to unlock
local model = script.Parent
-- This function recurses through a model's heirarchy and unlocks
-- every part that it encounters.
local function recursiveUnlock(object)
if object:IsA("BasePart") then
object.Locked = false
end
-- Call the same function on the children of the object
-- The recursive process stops if an object has no children
for _, child in pairs(object:GetChildren()) do
recursiveUnlock(child)
end
end
recursiveUnlock(model)
Mass
Mass は、部品のボリュームと密度の製品を説明する読み取り専用プロパティです。GetMass() 関数によって返されます。
- パーツのボリュームは、使用されている種類の と によって決まり、例えば のように、使用されている種類によって変わります。
- パーツの密度は、指定された場合は Material または CustomPhysicalProperties によって決定します。
Massless
このプロパティが有効になっている場合、部品は、マスがある別の部品に接着されている限り、アセンブリの総質量または粘性に貢献しません。
パーツが AssemblyRootPart に従って自分のルートパーツである場合、これはそのパーツに無視され、通常のパーツと同様に、マスと慣性をそのアセンブリに貢献します。マスレスなパーツは、アセンブリ内の他のすべてのパーツがマスレスでない限り、アセンブリのルートパーツには決してなってはならない必要があります。
これは、車のハンドリングに影響を与えたくないオプションのアクセサリーや、シンプルな衝突メッシュに接着された無重力レンダリングメッシュなど、車のハンドリングに影響を与えないものに便利かもしれません。
また、アセンブリ 、根部パーツの定義と使用方法を記述する記事を参照してください。
Material
Material プロパティでは、パーツのテクスチャとデフォルトの物理プロパティを設定できます (CustomPhysicalProperties が未設定の場合)。デフォルトの Plastic マテリアルは非常に軽いテクスチャを持ち、SmoothPlastic マテリアルは全くテクスチャがありません。DiamondPlate や Granite のような一部の材料テクスチャには、非常に目立つテクスチャがあります。各素材のテクスチャは、特に Foil 太陽光を異なり反映します。
このプロパティを設定し、CustomPhysicalProperties を有効にすると、素材のデフォルトの物理プロパティが使用されます。たとえば、DiamondPlate は非常に密度の高い材料であり、Wood は非常に軽い。パーツの密度は、地形水に浮かぶかどうかを決定します。
The Glass 物質変更レンダリング行動は、反射率 (Reflectance に似て) と視野歪みを適用して、中程度のグラフィック設定で描画します。効果は特に球形の部品に顕著です。Glass パーツの後ろにある半透明のパーツは見えません。
MaterialVariant
システムは、指定された MaterialVariant 名と MaterialVariant タイプで Material インスタンスを検索します。一致する MaterialVariant インスタンスを見つけることができれば、そのインスタンスを使用してデフォルトのマテリアルを置き換えます。デフォルトのマテリアルは、内蔵マテリアルまたは に指定されたオーバーライドマテリアルです。
Orientation
プロパティは、 X 、 Y 、および Z 軸を使用して、部品の回転を度数で説明します。回転は Y > X > Z 順序で適用されます。これは適切な ユーラー 角とは異なり、代わりに タイト-ブライアン 角が 偏航 , ピッチ , そして ロール を説明する角です。
このプロパティが異なる順序で回転を適用する CFrame.Angles() コンストラクターとどのように異なるかについても注意する価値があります ( Z > Y > X )。パーツの回転をより制御するには、代わりに CFrame が設定されることをお勧めします。
このプロパティを設定すると、この部分に接続された任意の Welds または Motor6Ds は、この部分が関連する他のパーツに対して移動できるように、マッチングする C0 または C1 プロパティを更新します。WeldConstraints も移行中に一時的に無効化され、再度有効化されます。
コードサンプル
This code sample rotates a part continually on the Y axis.
local part = script.Parent
local INCREMENT = 360 / 20
-- Rotate the part continually
while true do
for degrees = 0, 360, INCREMENT do
-- Set only the Y axis rotation
part.Rotation = Vector3.new(0, degrees, 0)
-- A better way to do this would be setting CFrame
--part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(degrees), 0)
task.wait()
end
end
PivotOffset
このプロパティは、パーツのピボットのオフセットを から指定し、それは が 乗算されたものと同じです。
これは、 ローカル スペースの位置にピボットを設定するのに便利ですが、パーツのピボットを 世界 スペースの位置に設定することも次のようにできます:
local Workspace = game:GetService("Workspace")local part = Workspace.BluePartlocal desiredPivotCFrameInWorldSpace = CFrame.new(0, 10, 0)part.PivotOffset = part.CFrame:ToObjectSpace(desiredPivotCFrameInWorldSpace)
コードサンプル
This code sample shows a custom function for resetting the pivot of a model back to the center of that model's bounding box.
local function resetPivot(model)
local boundsCFrame = model:GetBoundingBox()
if model.PrimaryPart then
model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame)
else
model.WorldPivot = boundsCFrame
end
end
resetPivot(script.Parent)
This code sample creates a clock at the origin with a minute, second, and hour hand, and makes it tick, displaying the local time.
local function createHand(length, width, yOffset)
local part = Instance.new("Part")
part.Size = Vector3.new(width, 0.1, length)
part.Material = Enum.Material.Neon
part.PivotOffset = CFrame.new(0, -(yOffset + 0.1), length / 2)
part.Anchored = true
part.Parent = workspace
return part
end
local function positionHand(hand, fraction)
hand:PivotTo(CFrame.fromEulerAnglesXYZ(0, -fraction * 2 * math.pi, 0))
end
-- Create dial
for i = 0, 11 do
local dialPart = Instance.new("Part")
dialPart.Size = Vector3.new(0.2, 0.2, 1)
dialPart.TopSurface = Enum.SurfaceType.Smooth
if i == 0 then
dialPart.Size = Vector3.new(0.2, 0.2, 2)
dialPart.Color = Color3.new(1, 0, 0)
end
dialPart.PivotOffset = CFrame.new(0, -0.1, 10.5)
dialPart.Anchored = true
dialPart:PivotTo(CFrame.fromEulerAnglesXYZ(0, (i / 12) * 2 * math.pi, 0))
dialPart.Parent = workspace
end
-- Create hands
local hourHand = createHand(7, 1, 0)
local minuteHand = createHand(10, 0.6, 0.1)
local secondHand = createHand(11, 0.2, 0.2)
-- Run clock
while true do
local components = os.date("*t")
positionHand(hourHand, (components.hour + components.min / 60) / 12)
positionHand(minuteHand, (components.min + components.sec / 60) / 60)
positionHand(secondHand, components.sec / 60)
task.wait()
end
Position
The Position プロパティは、Vector3 を使用してパーツの座標を説明します。パーツの位置 CFrame を反映しますが、設定することもできます。
このプロパティを設定すると、この部分に接続された任意の Welds または Motor6Ds は、この部分が関連する他のパーツに対して移動できるように、マッチングする C0 または C1 プロパティを更新します。WeldConstraints も移行中に一時的に無効化され、再度有効化されます。
ReceiveAge
パーツの物理がローカルクライアントまたはサーバーで最後に更新された時点から秒で表示されます。この値は、パーツに物理がないときに 0 になります (Anchored は true です)。
Reflectance
Reflectance プロパティは、パーツが天を反映する量を決定します。値 0 は、パーツが全すべて反射していないことを示し、値 1 は、パーツが完全に反射することを示します。
反射率は、パーツが完全に透明でない限り、Transparency に影響を受けません。その場合、反射率はすべてく表示されません。反射率は、パーツの Material によって無視されるか、無視されないかもしれません。
ResizeIncrement
ResizeIncrement プロパティは、Resize() メソッドで許可される最小のサイズ変更を説明する読み取り専用プロパティです。抽象クラスの実装によって異なります;たとえば、 は、個々のトラスセクションがサイズが 2×2×2 であるため、 にこのセットを 2×2×2 に設定します。
ResizeableFaces
ResizeableFaces プロパティは、パーツのサイズ変更が可能な異なる顔を説明するために Faces オブジェクトを使用します。ほとんどの BasePart の実装では、Part や WedgePart のように、このプロパティにはすべての顔が含まれます。しかし、 は、その種のパーツが持つべき長さの 2つのディメンションを持つように、 を2面に設定します。
このプロパティは、パーツの作成と操作のためのツールと一緒に最もよく使用され、そのコンテキストの外ではほとんど使用されません。このプロパティを持つ クラスは、パーツでサイズ変更できる顔のみを表示するために、このプロパティと一緒に使用できます。
コードサンプル
This code sample creates a Handles object and shows how to set the Faces property of the object. It also references ResizeableFaces of a part. Try placing this script in multiple kinds of parts to see how ResizeableFaces varies.
-- Put this Script in several kinds of BasePart, like
-- Part, TrussPart, WedgePart, CornerWedgePart, etc.
local part = script.Parent
-- Create a handles object for this part
local handles = Instance.new("Handles")
handles.Adornee = part
handles.Parent = part
-- Manually specify the faces applicable for this handle
handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left)
-- Alternatively, use the faces on which the part can be resized.
-- If part is a TrussPart with only two Size dimensions
-- of length 2, then ResizeableFaces will only have two
-- enabled faces. For other parts, all faces will be enabled.
handles.Faces = part.ResizeableFaces
RightSurface
RightSurface プロパティは、パーツの正の X 方向に使用される表面の種類を決定します。2つのパーツの面が互いに隣り合うと、間にジョイントが生成される可能性があります。
RootPriority
このプロパティは、-127 と 127 の間の整数で、ルートパーツソートの他のすべてのルールを上書きします。複数のパーツが Anchored ではなく、同じ Massless 値を共有している場合、より高い RootPriority を持つパーツが、より低い RootPriority を持つパーツより優先されます。
このプロパティを使用して、アセンブリのどの部分がルート部分であり、サイズ変更によってルート部分を安定させることができます。
また、アセンブリ 、根部パーツの定義と使用方法を記述する記事を参照してください。
Rotation
3軸のためのパーツの回転度です。
このプロパティを設定すると、この部分に接続された任意の Welds または Motor6Ds は、この部分が関連する他のパーツに対して移動できるように、マッチングする C0 または C1 プロパティを更新します。WeldConstraints も移行中に一時的に無効化され、再度有効化されます。
Size
パーツの Size プロパティは、 ビジュアル 寸法を決定し、ExtentsSize は物理エンジンで使用される実際のサイズを表示し、衝突検出 のように。個々の次元 (長さ、幅、高さ) は 0.001 と 2048 のように低く、または高くなることができます。サイズ寸法 以下は、パーツの寸法が のように視覚的に表示されます。
パーツの Size は、さまざまな追加方法で使用されます:
- To influence its mass as given by GetMass() 。
- By ParticleEmitter で、パーティクルが生成される領域を決定します。
- By BlockMesh により、レンダリングされた長方形のプリズムの一部を決定します。
- By SpecialMesh 特定の MeshTypes によって、レンダリングされたメッシュのサイズを決定する
- By SurfaceLight で照明するスペースを決定します。
コードサンプル
This code sample constructs a pyramid by stacking parts that get progressively smaller. It also colors the parts so they blend between a start color and end color.
local TOWER_BASE_SIZE = 30
local position = Vector3.new(50, 50, 50)
local hue = math.random()
local color0 = Color3.fromHSV(hue, 1, 1)
local color1 = Color3.fromHSV((hue + 0.35) % 1, 1, 1)
local model = Instance.new("Model")
model.Name = "Tower"
for i = TOWER_BASE_SIZE, 1, -2 do
local part = Instance.new("Part")
part.Size = Vector3.new(i, 2, i)
part.Position = position
part.Anchored = true
part.Parent = model
-- Tween from color0 and color1
local perc = i / TOWER_BASE_SIZE
part.Color = Color3.new(
color0.R * perc + color1.R * (1 - perc),
color0.G * perc + color1.G * (1 - perc),
color0.B * perc + color1.B * (1 - perc)
)
position = position + Vector3.new(0, part.Size.Y, 0)
end
model.Parent = workspace
TopSurface
TopSurface プロパティは、パーツの正の Y 方向に使用される表面の種類を決定します。2つのパーツの面が互いに隣り合うと、間にジョイントが生成される可能性があります。
Transparency
The Transparency プロパティは、0 から 1 までのスケールで、0 が完全に見える (不透明)、1 が完全に見えない (全くレンダリングされない)パーツの表示を制御します。
完全に透明なパーツはすべてくレンダリングされませんが、部分的に透明なオブジェクトには、重要なレンダリングコストがかかります。多くの透明なパーツがあると、パフォーマンスに影響を与える可能性がありま履行。
透明なパーツが重複すると、レンダリング順序が予測できないようになるため、半透明のパーツの重複を避ける必要があります。
また、LocalTransparencyModifier はローカルクライアントにしか表示されない Transparency の乗数としても見てください。
コードサンプル
This code sample shows how a part can fade away when touched by a Humanoid then reappear a moment after to create a passable door.
-- Paste into a Script inside a tall part
local part = script.Parent
local OPEN_TIME = 1
-- Can the door be opened at the moment?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("Black")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("Bright blue")
end
local function onTouch(otherPart)
-- If the door was already open, do nothing
if debounce then
print("D")
return
end
-- Check if touched by a Humanoid
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("not human")
return
end
-- Perform the door opening sequence
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()
方法
AngularAccelerationToTorque
パラメータ
戻り値
ApplyAngularImpulse
この部品の組み立てに瞬間的な角力パルスを適用し、組み立てを回転させます。
パルスからの結果の角速度は、アセンブリの mass に依存します。よって、より大規模なアセンブリを移動するには、より高いインパルスが必要です。インパルスは、爆発や衝突など、すぐに力を適用したい場合に便利です。
パーツがサーバーに所有されている場合、この関数はサーバーから呼び出されなければなりません (サーバーではなく、 または で設定された から呼び出されます)。パーツが 自動 所有権を介してクライアントに所有されている場合、この関数はクライアントスクリプトから、またはサーバースクリプトから呼び出すことができます;サーバーが所有するパーツにクライアントスクリプトを呼び出すと、効果はありません。
パラメータ
アセンブリに適用される角度パルスベクトル。
戻り値
ApplyImpulse
この機能は、この部分の組み立てに瞬間力パルスを適用します。
力はアセンブリの center of mass に適用されるので、結果の動きは線形になるだけです。
パルスからの結果の速度は、アセンブリの mass に依存します。よって、より大規模なアセンブリを移動するには、より高いインパルスが必要です。インパルスは、爆発や衝突など、すぐに力を適用したい場合に便利です。
パーツがサーバーに所有されている場合、この関数はサーバーから呼び出されなければなりません (サーバーではなく、 または で設定された から呼び出されます)。パーツが 自動 所有権を介してクライアントに所有されている場合、この関数はクライアントスクリプトから、またはサーバースクリプトから呼び出すことができます;サーバーが所有するパーツにクライアントスクリプトを呼び出すと、効果はありません。
パラメータ
アセンブリに適用される線形インパルスベクトル。
戻り値
ApplyImpulseAtPosition
この機能は、ワールドスペースの指定された位置にこのパーツの組み立てに瞬間力パルスを適用します。
位置がアセンブリの center of mass にない場合、パルスは位置および回転移動を引き起こします。
パルスからの結果の速度は、アセンブリの mass に依存します。よって、より大規模なアセンブリを移動するには、より高いインパルスが必要です。インパルスは、開発者が爆発や衝突など、すぐに力を適用したい場合に便利です。
パーツがサーバーに所有されている場合、この関数はサーバーから呼び出されなければなりません (サーバーではなく、 または で設定された から呼び出されます)。パーツが 自動 所有権を介してクライアントに所有されている場合、この関数はクライアントスクリプトから、またはサーバースクリプトから呼び出すことができます;サーバーが所有するパーツにクライアントスクリプトを呼び出すと、効果はありません。
パラメータ
戻り値
CanCollideWith
パーツが互いに衝突できるかどうかを返します。この機能は、2つのパーツの衝突グループを考慮します。この機能は、指定された部分がベースパーツでない場合にエラーが発生します。
パラメータ
衝突可能性がチェックされている指定のパーツ。
戻り値
パーツが互いに衝突できるかどうか。
CanSetNetworkOwnership
CanSetNetworkOwnership 関数は、パーツのネットワーク所有権を設定できるかどうかをチェックします。
関数の返却値は、エラーを発見せずに BasePart:SetNetworkOwner() または BasePart:SetNetworkOwnershipAuto() を呼び出すことができるかどうかを確認します。ネットワーク所有権を変更/読み込みできるかどうか、または理由を文字列として返すかどうかを真に返します。It returns true if you can modify/read the network ownership, or returns false and the reason you can't, as a string.
戻り値
ネットワークの所有権と理由を変更または読み込みできるかどうか
コードサンプル
This example checks whether or not the network ownership of the first BasePart named Part in the Workspace can be set.
local part = workspace:FindFirstChild("Part")
if part and part:IsA("BasePart") then
local canSet, errorReason = part:CanSetNetworkOwnership()
if canSet then
print(part:GetFullName() .. "'s Network Ownership can be changed!")
else
warn("Cannot change the Network Ownership of " .. part:GetFullName() .. " because: " .. errorReason)
end
end
GetConnectedParts
剛性ジョイントでオブジェクトに接続されたパーツのテーブルを返します。
if recursive が true である場合、この関数は、ベースパーツに堅く接続されたアセンブリのすべてのパーツを返します。
剛性ジョイント
ジョイントが 2 つのパーツを接続するとき (Part0 → Part1) 、ジョイントは 剛性 ですが、Part1 の物理が完全にロックダウンされている場合は Part0 です。これは次の共同タイプにのみ適用されます:
パラメータ
戻り値
GetJoints
このパーツに接続されているすべてのジョイントまたは制限を返す。
戻り値
パーツに接続されたすべてのジョイントまたは制限の配列。
GetMass
GetMass は、読み取り専用の Mass プロパティの値を返します。
この機能は、マスプロパティよりも先行します。後方互換性のために、マスプロパティを直接使用する必要があります。
戻り値
部品の質量。
コードサンプル
This example creates a new part, myPart, in the game's Workspace, with dimensions 4x6x4 studs. The part is also anchored.
Then, myMass is set to equal the mass of the new part. The mass of the part is printed at the end of the print statement:
My part's mass is ...
local myPart = Instance.new("Part")
myPart.Size = Vector3.new(4, 6, 4)
myPart.Anchored = true
myPart.Parent = workspace
local myMass = myPart:GetMass()
print("My part's mass is " .. myMass)
GetNetworkOwner
この部分のネットワーク所有者である現在のプレイヤーを返すか、nil は、サーバーの場合。
戻り値
この部分のネットワーク所有者である現在のプレイヤー、または nil サーバーの場合。
GetNetworkOwnershipAuto
ゲームエンジンが自動的にこの部分のネットワーク所有者を決定する場合、真を返します。
戻り値
ゲームエンジンがこの部分のネットワーク所有者を自動的に決定するかどうか。
GetNoCollisionConstraints
戻り値
GetRootPart
アセンブリのベース部分を返します。CFrame を使用してパーツのアセンブリを移動するとき。このベースパーツを移動することが重要です(これに連結した他のパーツはすべて移動します)。詳しい情報は、アセンブリ 記事で利用可能です。
この機能は AssemblyRootPart プロパティよりも古く、後方互換性のためにサポートされ続けていますが、直接 AssemblyRootPart を使用する必要があります。
戻り値
アセンブリのベースパーツ (一連のパーツを結合したコレクション)
GetTouchingParts
このパーツと物理的に相互作用するすべてのパーツのテーブルを返します。パーツ自体が [CanCollide] を false に設定している場合、この関数はパーツに TouchInterest オブジェクトが付属していない限り、空のテーブルを返します (つまり、タッチイベントに何かが接続されています)。接しているが交差していないパーツはタッチとして考えられません。この機能は、上記の特別な WorldRoot:GetPartsInPart() 規則を避け、より多くの柔軟性を提供する TouchInterest 機能よりも先行します。代わりに WorldRoot:GetPartsInPart() を使用します。
戻り値
このパーツと衝突する可能性のあるすべてのパーツの表。
GetVelocityAtPosition
このパーツに対する位置に関連して、部品の組み立ての線速度を返します。ルートパーツ以外のアセンブリの中の部品の線速度を識別するために使用できます。アセンブリに角速度がない場合、線速度は常にすべての位置で同じです。
パラメータ
戻り値
IsGrounded
オブジェクトがそれを保持するパーツに接続されている場合 (例: Anchored パーツ) は真を返し、そうでない場合は false を返します。Anchored パーツがあるアセンブリでは、他のすべてのパーツがグランドされます。
戻り値
オブジェクトがそれを保持するパーツに接続されているかどうか。
Resize
Studio のサイズ変更ツールを使用するのと同じように、オブジェクトのサイズを変更します。
パラメータ
サイドを再設定する。
指定された側で成長/縮小する量。
戻り値
パーツがサイズ変更されるかどうか。
SetNetworkOwner
指定されたプレイヤーをこのネットワークの所有者とすべての接続部品の所有者とします。playerInstance が nil のとき、サーバーはプレイヤーではなくオーナーになります。
パラメータ
パートのネットワーク所有権がプレイヤーに与えられている。
戻り値
SetNetworkOwnershipAuto
ゲームエンジンが動的に、パーツの物理を処理する人 (クライアントの 1 人またはサーバー) を決定できます。
戻り値
TorqueToAngularAcceleration
パラメータ
戻り値
IntersectAsync
部品とその他のパーツの交差する幾何学から新しい IntersectOperation を作成し、指定された配列に追加します。サポートされるのは Parts だけで、Terrain や MeshParts はサポートされません。Clone() と同様、返されたオブジェクトには Parent が設定されていません。
呼び出す側の次のプロパティが、結果の IntersectOperation に適用されます:
次の画像比較では、IntersectAsync() はブルーブロックを含むテーブルを使用して紫のブロックに呼び出されます。結果の IntersectOperation は、両方のパーツの交差する幾何学の形に解決します。

<figcaption>個別のパーツ</figcaption>

<figcaption>結果の <code>Class.IntersectOperation</code></figcaption>
ノート
- 成功した交差操作の後、オリジナルのパーツはそのまま残ります。ほとんどの場合、Destroy() オリジナルのパーツすべてと、返されたIntersectOperation を呼び出すBasePart と同じ場所に親属させるべきです。
- 交差操作により、20,000以上の三角形を持つパーツが生成された場合、20,000三角形に簡素化されます。
パラメータ
交差点に参加しているオブジェクト。
結果の Enum.CollisionFidelity に対する値 IntersectOperation 。
結果の Enum.RenderFidelity 値の PartOperation 。
戻り値
結果 IntersectOperation デフォルト名で 交差 。
SubtractAsync
パーツから新しい UnionOperation を作成し、指定されたアレイに含まれるパーツによって占有される幾何学を除きます。サポートされるのは Parts だけで、Terrain や MeshParts はサポートされません。Clone() と同様、返されたオブジェクトには Parent が設定されていません。
減算により結果のユニオンが空になることに注意してください。操作が完全に空の幾何学になる場合、失敗します。
次の画像比較では、SubtractAsync() は紫のブロックを含むテーブルを使用して青いシリンダーに呼び出されます。結果の UnionOperation は、ブロックの幾何学をシリンダーから削除する形状に解決します。

<figcaption>個別のパーツ</figcaption>

<figcaption>結果の <code>Class.UnionOperation</code></figcaption>
パラメータ
削除に参加するオブジェクト。
結果の Enum.CollisionFidelity に対する値 UnionOperation 。
結果の Enum.RenderFidelity 値の PartOperation 。
戻り値
結果 UnionOperation デフォルト名 Union で。
コードサンプル
This example demonstrates how to subtract part(s) from another BasePart to form a negated UnionOperation.
local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- Perform subtract operation
local success, newSubtract = pcall(function()
return mainPart:SubtractAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newSubtract then
newSubtract.Position = mainPart.Position
newSubtract.Parent = Workspace
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end
UnionAsync
パーツから新しい UnionOperation を作成し、指定された配列内のパーツによって占有された幾何学を加えます。サポートされるのは Parts だけで、Terrain や MeshParts はサポートされません。Clone() と同様、返されたオブジェクトには Parent が設定されていません。
呼び出す側の次のプロパティが、結果の UnionOperation に適用されます:
次の画像比較では、UnionAsync() は紫のシリンダーを含むテーブルを使用してブルーブロックに呼び出されます。結果の UnionOperation は、両方のパーツの組み合わせた幾何学の形に解決します。

<figcaption>個別のパーツ</figcaption>

<figcaption>結果の <code>Class.UnionOperation</code></figcaption>
ノート
- 成功した結合操作の後、オリジナルのパーツはそのまま残ります。ほとんどの場合、Destroy() オリジナルのパーツすべてと、返されたUnionOperation を呼び出すBasePart と同じ場所に親属させるべきです。
- ユニオン操作が 20,000 以上の三角形を持つパーツになる場合、20,000 三角形に簡素化されます。
パラメータ
呼び出し部分との結合に参加するオブジェクト。
結果の Enum.CollisionFidelity に対する値 UnionOperation 。
結果の Enum.RenderFidelity 値の PartOperation 。
戻り値
結果 UnionOperation デフォルト名 Union で。
コードサンプル
This example demonstrates how to combine the geometry of one BasePart with the geometry of other part(s) to form a UnionOperation.
local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- Perform union operation
local success, newUnion = pcall(function()
return mainPart:UnionAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newUnion then
newUnion.Position = mainPart.Position
newUnion.Parent = Workspace
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end
イベント
TouchEnded
パーツが BasePart.Touched と同じ条件で他のパーツに触れなくなったときに発火します。
このイベントは、Workspace.TouchesUseCollisionGroups と一緒に動作して、衝突グループ が検出に認識されるかどうかを指定します。
パラメータ
コードサンプル
This code sample creates a BillboardGui on a part that displays the number of parts presently touching it.
local part = script.Parent
local billboardGui = Instance.new("BillboardGui")
billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.Adornee = part
billboardGui.AlwaysOnTop = true
billboardGui.Parent = part
local tl = Instance.new("TextLabel")
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
tl.Parent = billboardGui
local numTouchingParts = 0
local function onTouch(otherPart)
print("Touch started: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("Touch ended: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
Touched
タッチ イベントは、パーツが他のパーツと接触すると発動します。たとえば、if パーツA が パーツB に衝突すると、PartA.Touched が パーツB で発火し、PartB.Touched が パーツA で発火します。
このイベントは物理的な移動の結果としてのみ発射されるので、CFrame プロパティが変更されてパーツが他のパーツに重複するようになった場合は発射しません。これは、関与するパーツの少なくとも 1 つが、衝突時に しない 必須であることを意味します。
このイベントは、Workspace.TouchesUseCollisionGroups と一緒に動作して、衝突グループ が検出に認識されるかどうかを指定します。
パラメータ
指定されたパーツに接触した他のパーツ。
コードサンプル
This code sample creates a BillboardGui on a part that displays the number of parts presently touching it.
local part = script.Parent
local billboardGui = Instance.new("BillboardGui")
billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.Adornee = part
billboardGui.AlwaysOnTop = true
billboardGui.Parent = part
local tl = Instance.new("TextLabel")
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
tl.Parent = billboardGui
local numTouchingParts = 0
local function onTouch(otherPart)
print("Touch started: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("Touch ended: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
This code sample demonstrates how to connect the BasePart.Touched event of multiple parts in a Model to one function.
local model = script.Parent
local function onTouched(otherPart)
-- Ignore instances of the model coming in contact with itself
if otherPart:IsDescendantOf(model) then
return
end
print(model.Name .. " collided with " .. otherPart.Name)
end
for _, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
child.Touched:Connect(onTouched)
end
end