PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

In-Game Solid Modeling

In-Game Solid Modeling

Sep 07 2018, 1:01 PM PST 5 min

Detailed Articles/3D Modeling with Parts|solid models can be created using the Union and Negate tools, not only in Studio but also while your game is being played. This can be used to create some truly unique game concepts!

Solid Modeling APIs

UnionAsync()

The BasePart/UnionAsync|UnionAsync() function must be called on a BasePart. It requires an array of one or more parts (otherParts) to union with the calling BasePart.

local part = workspace.Part1
local otherParts = {workspace.Part2, workspace.Part3, workspace.Part4}
 
-- Perform union operation
local newUnion = part:UnionAsync(otherParts)

SubtractAsync()

The BasePart/SubtractAsync|SubtractAsync() function also requires an array of one or more parts to subtract from the calling BasePart.

local part = workspace.Part1
local otherParts = {workspace.Part2, workspace.Part3, workspace.Part4}
 
-- Perform union operation
local newUnion = part:SubtractAsync(otherParts)

Basic Demonstration

Let’s test out in-game solid modeling with a quick demo script! You can copy and paste this into a Script within ServerScriptService, or wherever is most convenient.

-- Create a basic window part
local window = Instance.new("Part")
window.Size = Vector3.new(10, 16, 0.5)
window.Material = "Glass"
window.BrickColor = BrickColor.new("Persimmon")
window.Reflectance = 0.2
window.Transparency = 0.5
window.Position = Vector3.new(0, 8, 0)
window.Anchored = true
window.Parent = game.Workspace

-- Create a part to subtract from window
local subBlock = Instance.new("Part")
subBlock.Size = Vector3.new(4, 4, 4)
subBlock.Material = "SmoothPlastic"
subBlock.CanCollide = false
subBlock.Position = Vector3.new(0, 8, 0)
subBlock.Anchored = true
subBlock.Parent = game.Workspace

wait(2)

-- Subtract smaller block from window
local success, newUnion = pcall(function()
	return window:SubtractAsync({subBlock})
end)

if success and newUnion then
	newUnion.Position = window.Position
	newUnion.Anchored = true
	newUnion.Parent = game.Workspace
	-- Remove original parts
	window:Destroy()
	subBlock:Destroy()
end

In this script, a basic order of operations occurs:

  1. A red glass window is created in the center of the place (lines 2-10).
  2. A smaller block is created in the center of the window part (lines 13-19).
  3. After 2 seconds, BasePart/SubtractAsync|SubtractAsync() is called on the window, using the smaller block as the part to subtract.
  1. If successful, the resulting part is returned with a name of Union. This instance will not be parented to the workspace, so it’s your job to parent it back into the game world.

Solid-Modeling Playground

Now that you understand basic in-game solid modeling, experience it within a sample place!

Rotating Windows

Blast pieces out of rotating windows or fuse new material onto them. Includes a helper module script that rebuilds mechanisms with constraints and attachments!
Tags:
  • model
  • parts
  • union
  • negate