Class
Terrain
NotCreatable
Terrain lets you to create dynamically morphable environments.
The Terrain class lets you create dynamically morphable environments. It is
based on a 4×4×4 grid of cells, where each cell has a number
between 0 and 1 representing how much the geometry should occupy the cell,
and the material of the cell. The occupancy determines how the cell will morph
together with surrounding cells, and the result is the illusion of having no
grid constraint.
For more information, see Terrain.
Properties 10#
Decorationboolean | Enables or disables terrain decoration.ReadSafeNotScriptable |
GrassLengthfloat | Specifies the length of animated grass.ReadSafeNotScriptable |
IsSmoothboolean | Returns true if the game is using the smooth terrain system.ReadSafeDeprecatedReadOnlyNotReplicated |
MaterialColorsBinaryString | Represents the editor for the Material Color feature and cannot be edited by scripts.ReadSafeNotScriptable |
MaxExtentsRegion3int16 | Displays the boundaries of the largest possible editable region.ReadSafeReadOnlyNotReplicated |
WaterColorColor3 | The tint of Terrain water.ReadSafe |
WaterReflectancefloat | Controls how opaque Terrain water reflections are.ReadSafe |
WaterTransparencyfloat | The transparency of Terrain water.ReadSafe |
WaterWaveSizefloat | Sets the maximum height of Terrain water waves in studs.ReadSafe |
WaterWaveSpeedfloat | Sets how many times Terrain water waves will move up and down per
minute.ReadSafe |
Decoration: boolean#
NotScriptableReadSafe
Currently enables or disables animated grass on the
Grass terrain material, although future
modifications of this property may control additional decorative features.
GrassLength: float#
NotScriptableReadSafe
Specifies the length of animated grass on the Grass
terrain material, assuming Decoration is
enabled. Valid values are between 0.1 and 1.
IsSmooth: boolean#
ReadOnlyNotReplicatedDeprecatedReadSafeDeprecated
Deprecated. The legacy terrain engine has been removed, so this property will always
be true.
Returns true if the game is using the smooth terrain system.
MaterialColors: BinaryString#
NotScriptableReadSafe
MaterialColors represents the editor for the Material Color feature
and cannot be edited by scripts.
To get the color of a material, use Terrain:GetMaterialColor(). To
set the color of a material, use Terrain:SetMaterialColor().
MaxExtents: Region3int16#
ReadOnlyNotReplicatedReadSafe
Displays the boundaries of the largest possible editable region as a
Region3int16. The returned value spans from
(-32000, -32000, -32000) to (32000, 32000, 32000) in cell coordinates,
where each cell is 4 studs wide. This corresponds to a world-space volume
of -128,000 to 128,000 studs on each axis. The property is read-only.
WaterColor: Color3#
ReadSafe
The tint color applied to Terrain water. This Color3 value is
blended with the water's base appearance to shift its overall hue. The
default value is [0.05, 0.33, 0.36] (a dark teal).
WaterReflectance: float#
ReadSafe
Controls how opaque the reflections on Terrain water are, on a scale of
0 (no reflections) to 1 (fully opaque reflections). The default value
is 1.
WaterTransparency: float#
ReadSafe
The transparency of Terrain water, on a scale of 0 (fully opaque) to
1 (fully transparent). The default value is 0.3.
WaterWaveSize: float#
ReadSafe
Sets the maximum height of Terrain water waves in studs. This is
currently constrained to between 0 and 1.
WaterWaveSpeed: float#
ReadSafe
Sets how many times Terrain water waves will move up and down per
minute. This is currently constrained to between 0 and 100.
Methods 29#
| AutowedgeCell | Obsolete function which no longer does anything.Deprecated |
| AutowedgeCells | Obsolete function which no longer does anything.Deprecated |
| CellCenterToWorld | Returns the world position of the center of the terrain cell. |
| CellCornerToWorld | Returns the position of the lower-left-forward corner of the grid cell. |
| Clear | Clears all terrain. |
| ConvertToSmooth | Transforms the legacy terrain engine into the new terrain engine.PluginSecurity securityDeprecated |
| CopyRegion | Stores a chunk of terrain into a TerrainRegion object so it can be
loaded back later. |
| CountCells | Returns the number of non-empty cells in the terrain. |
| FillBall | Fills a ball of smooth terrain in a given space. |
| FillBlock | Fills a block of smooth terrain with a given location, rotation, size, and material. |
| FillCylinder | Fills a cylinder of smooth terrain in a given space. |
| FillRegion | Fills a Region3 space with smooth terrain. |
| FillWedge | Fills a wedge-shaped volume of terrain with the given Material. |
| GetCell | Returns the closest cell material from the legacy terrain engine that matches the smooth terrain voxel specified.Deprecated |
| GetMaterialColor | Returns current terrain material color for specified terrain material.Safe |
| GetWaterCell | Returns true if the cell is a water cell.Deprecated |
| PasteRegion | Applies a chunk of terrain to the Terrain object. |
| ReadVoxelChannels | Returns a region of terrain voxel data in table format based on the channel names.SafeCustomLuaState |
| ReadVoxels | Returns a certain region of smooth terrain in table format.SafeCustomLuaState |
| ReplaceMaterial | Replaces the terrain of a material within a region with another material. |
| SetCell | Sets the occupancy and material of a specific terrain voxel.Deprecated |
| SetCells | Sets the occupancy and material of all terrain voxels in a specific region.Deprecated |
| SetMaterialColor | Sets current terrain material color for specified terrain material. |
| SetWaterCell | Sets the specified terrain voxel's material to water and sets its
occupancy to 1.Deprecated |
| WorldToCell | Returns the grid cell location that contains the position point. |
| WorldToCellPreferEmpty | Returns the grid cell location that contains the position point, preferring empty grid cells when position is on a grid edge. |
| WorldToCellPreferSolid | Returns the grid cell location that contains the point position, preferring non-empty grid cells when position is on a grid edge. |
| WriteVoxelChannels | Sets a region of terrain using a dictionary of voxel channel data.CustomLuaState |
| WriteVoxels | Sets a certain region of smooth terrain using table format.CustomLuaState |
AutowedgeCell(x: int, y: int, z: int): boolean#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Obsolete function which no longer does anything.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell. | |
y | int | The Y coordinate of the terrain cell. | |
z | int | The Z coordinate of the terrain cell. |
Returns
boolean— Always returnstrue; the function no longer performs any operation.
AutowedgeCells(region: Region3int16): ()#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Obsolete function which no longer does anything. It was part of the legacy terrain engine that has since been removed, so calling it on a region has no effect.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3int16 | The Region3int16 specifying the region of terrain cells to
process. |
Returns
()
CellCenterToWorld(x: int, y: int, z: int): Vector3#
Returns the world position of the center of the terrain cell at grid
coordinates (x, y, z). Each terrain cell is 4×4×4 studs, so
this method returns the position of the lower-left-forward corner of the
cell plus an offset of (2, 2, 2) studs.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell in grid space. | |
y | int | The Y coordinate of the terrain cell in grid space. | |
z | int | The Z coordinate of the terrain cell in grid space. |
CellCornerToWorld(x: int, y: int, z: int): Vector3#
Returns the world position of the lower-left-forward corner of the terrain
cell at grid coordinates (x, y, z). Each terrain cell is
4×4×4 studs, so the corner position is
(x * 4, y * 4, z * 4).
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell in grid space. | |
y | int | The Y coordinate of the terrain cell in grid space. | |
z | int | The Z coordinate of the terrain cell in grid space. |
Clear(): ()#
Clears the entire terrain, removing all material and occupancy data from
every voxel. After calling this method, the Terrain object contains no
geometry until new terrain is written via methods such as
FillBlock() or
WriteVoxels().
Returns
()
ConvertToSmooth(): ()#
DeprecatedPluginSecurity securityDeprecated
Deprecated. Since all places now automatically use the new terrain engine, this method is obsolete.
Transforms the legacy terrain engine into the new terrain engine. All places now automatically use the new terrain engine, so this method is obsolete.
Returns
()
CopyRegion(region: Region3int16): TerrainRegion#
Stores a chunk of terrain into a TerrainRegion object so it can be
loaded back later. Note that TerrainRegion data does not replicate
between server and client.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3int16 | The Region3int16 defining the area of terrain to copy, in
cell coordinates. |
Returns
TerrainRegion— ATerrainRegioncontaining the copied voxel data from the specified region.
CountCells(): int#
Returns the approximate number of non-empty cells in the terrain. A cell is considered non-empty when it has a material other than Air and an occupancy greater than zero. This count is an approximation and can be used to quickly gauge how much terrain geometry exists in the place.
Returns
int— The approximate number of non-empty terrain cells.
FillBall(center: Vector3, radius: float, material: Material): ()#
Fills a spherical volume of smooth terrain centered at center with the
given radius (in studs) and Material. Voxels within the sphere
are set to full occupancy with the specified material. Existing terrain
inside the sphere is overwritten.
| Name | Type | Default | Description |
|---|---|---|---|
center | Vector3 | The position of the center of the terrain ball. | |
radius | float | The radius in studs of the terrain ball. | |
material | Material | The Material of the terrain ball. |
Returns
()
FillBlock(cframe: CFrame, size: Vector3, material: Material): ()#
Fills an oriented rectangular volume of smooth terrain at the position and
rotation specified by cframe, with the dimensions given by size (in
studs), using the specified Material. Because the block is oriented
by a CFrame, it can be rotated to any angle. Existing terrain
inside the volume is overwritten.
| Name | Type | Default | Description |
|---|---|---|---|
cframe | CFrame | The position and orientation of the terrain block. | |
size | Vector3 | The size in studs of the square block (both the height and width). | |
material | Material | The Material of the terrain block. |
Returns
()
FillCylinder(cframe: CFrame, height: float, radius: float, material: Material): ()#
Fills a cylinder of smooth terrain in a given space. The space is defined
using a CFrame, height, and radius.
| Name | Type | Default | Description |
|---|---|---|---|
cframe | CFrame | The position and orientation of the terrain cylinder. | |
height | float | The height in studs of the terrain cylinder. | |
radius | float | The radius in studs of the terrain cylinder. | |
material | Material | The Material of the terrain cylinder. |
Returns
()
FillRegion(region: Region3, resolution: float, material: Material): ()#
Fills an axis-aligned Region3 volume of smooth terrain with the
specified Material at full occupancy. The resolution parameter
must be exactly 4. The region must be aligned to the voxel grid; use
Region3:ExpandToGrid() to align a region before calling.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3 | The Region3 to fill, which must be aligned to the voxel
grid. | |
resolution | float | The voxel resolution; must be exactly 4. | |
material | Material | The Material to fill the region with. |
Returns
()
FillWedge(cframe: CFrame, size: Vector3, material: Material): ()#
This method fills a wedge-shaped volume of Terrain with the given
Material and the area's CFrame and size. The orientation
of the wedge is the same as an equivalent WedgePart.
| Name | Type | Default | Description |
|---|---|---|---|
cframe | CFrame | The position and orientation of the wedge to fill. | |
size | Vector3 | The size of the wedge to fill. | |
material | Material | The material with which the wedge will be filled. |
Returns
()
GetCell(x: int, y: int, z: int): Tuple#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Returns the closest cell material from the legacy terrain engine that matches the smooth terrain voxel specified.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell. | |
y | int | The Y coordinate of the terrain cell. | |
z | int | The Z coordinate of the terrain cell. |
Returns
Tuple— A tuple containing the legacy cell material, block type, and orientation of the specified cell.
GetMaterialColor(material: Material): Color3#
Safe
GetWaterCell(x: int, y: int, z: int): Tuple#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Returns true if the cell is a water cell.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell. | |
y | int | The Y coordinate of the terrain cell. | |
z | int | The Z coordinate of the terrain cell. |
Returns
Tuple— A tuple containing whether the cell has water, the water force, and the water direction.
PasteRegion(region: TerrainRegion, corner: Vector3int16, pasteEmptyCells: boolean): ()#
Applies a chunk of terrain to the Terrain object. Note that
TerrainRegion data does not replicate between server and client.
| Name | Type | Default | Description |
|---|---|---|---|
region | TerrainRegion | The TerrainRegion to paste, previously obtained from
Terrain:CopyRegion(). | |
corner | Vector3int16 | The Vector3int16 cell coordinate at which to place the
lower-left-forward corner of the region. | |
pasteEmptyCells | boolean | Whether to overwrite existing terrain with empty (air) cells from the region. |
Returns
()
ReadVoxelChannels(region: Region3, resolution: float, channelIds: Array): Dictionary#
CustomLuaStateSafe
Returns voxel data from a region of terrain, separated by channel. Unlike
ReadVoxels(), this method lets you specify
exactly which channels to read (SolidMaterial, SolidOccupancy, and/or
LiquidOccupancy), and returns a dictionary keyed by channel ID. The
region must be aligned to the voxel grid, resolution must be 4, and
the region cannot exceed 4,194,304 voxels.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3 | Target region to read from. Must be aligned to the voxel grid. Will throw an error if region is too large; limit is currently 4194304 voxels³. | |
resolution | float | Voxel resolution. Must be 4. | |
channelIds | Array | Array of channel IDs (strings) that need to be accessed from the voxel
data. Each channel ID represents a type of data that's stored in
voxel. Current supported IDs are
{"SolidMaterial", "SolidOccupancy", "LiquidOccupancy"}. |
Returns
Dictionary— Returns voxel data as a dictionary based on thechannelIdsinput. Keys represent each channel ID with their respective value as an array of 3D data.SolidMaterial— TheMaterialmaterial of the voxel. Note thatWateris not supported anymore; instead, a voxel that contains water will have a value ofLiquidOccupancy.SolidOccupancy— The occupancy of the voxel's material as specified in theSolidMaterialchannel. This is a value between 0 (empty) and 1 (full).LiquidOccupancy— Specifies the occupancy of theWatermaterial in a voxel as a value between 0 (no water) and 1 (full of water). If theSolidOccupancyis 1 and theSolidMaterialis notAir, this will be 0.
The dictionary also contains a
Sizekey with a value representing the 3D array size of each channel data.
ReadVoxels(region: Region3, resolution: float): Tuple#
CustomLuaStateSafe
Returns the voxel data for a region of smooth terrain as two 3D arrays:
materials (an array of Material values) and occupancies (an
array of numbers between 0 and 1). The region must be aligned to the
voxel grid, resolution must be 4, and the region cannot exceed
4,194,304 voxels. For more granular channel control, see
ReadVoxelChannels().
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3 | Target region to read from. Must be aligned to the voxel grid. Will throw an error if region is too large. The limit is currently 4194304 voxels³. | |
resolution | float | Voxel resolution. Must be 4. |
Returns
Tuple—Returns raw voxel data as two 3D arrays.
materials- 3D array ofMaterialfrom the target area. Also contains a Size field, equal to the dimensions of the nested arrays.occupancies- 3D array of occupancy values from the target area. Also contains a Size field, equal to the dimensions of the nested arrays.
ReplaceMaterial(region: Region3, resolution: float, sourceMaterial: Material, targetMaterial: Material): ()#
ReplaceMaterial replaces terrain of a certain Material within a
Region3 with another material. Essentially, it is a
find-and-replace operation on Terrain materials.
When calling this method, the resolution parameter must be exactly 4.
Additionally, region must be aligned to the terrain materials grid, such
that the components of the region's minimum and maximum points must be
divisible by 4. Use Region3:ExpandToGrid() to make a region
compatible with this function.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3 | The region in which the replacement operation will occur. | |
resolution | float | The resolution at which the replacement operation will take place; at
the moment this must be exactly 4. | |
sourceMaterial | Material | The old material that shall be replaced. | |
targetMaterial | Material | The new material. |
Returns
()
SetCell(x: int, y: int, z: int, material: CellMaterial, block: CellBlock, orientation: CellOrientation): ()#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Sets the occupancy of the specified terrain voxel to 1 and sets its
material to the closest smooth terrain material that matches the cell
material.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell. | |
y | int | The Y coordinate of the terrain cell. | |
z | int | The Z coordinate of the terrain cell. | |
material | CellMaterial | The CellMaterial to set for the cell. | |
block | CellBlock | The CellBlock shape type for the cell. | |
orientation | CellOrientation | The CellOrientation rotation for the cell. |
Returns
()
SetCells(region: Region3int16, material: CellMaterial, block: CellBlock, orientation: CellOrientation): ()#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Sets the occupancy of all terrain voxels in the specified region to 1
and sets their materials to the closest smooth terrain material that
matches the cell material.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3int16 | The Region3int16 specifying the area of terrain cells to
set. | |
material | CellMaterial | The CellMaterial to apply to all cells in the region. | |
block | CellBlock | The CellBlock shape type to apply to all cells in the region. | |
orientation | CellOrientation | The CellOrientation rotation to apply to all cells in the
region. |
Returns
()
SetMaterialColor(material: Material, value: Color3): ()#
Sets current terrain material color for specified terrain material. Terrain material will shift its base color toward specified color.
| Name | Type | Default | Description |
|---|---|---|---|
material | Material | The Material whose terrain color to change. | |
value | Color3 | The Color3 to apply as the new color tint for the material. |
Returns
()
SetWaterCell(x: int, y: int, z: int, force: WaterForce, direction: WaterDirection): ()#
DeprecatedDeprecated
Deprecated. This item is a deprecated function of a legacy Terrain engine that
has been removed. Do not use it for new work.
Sets the specified terrain voxel's material to water and sets its
occupancy to 1.
| Name | Type | Default | Description |
|---|---|---|---|
x | int | The X coordinate of the terrain cell. | |
y | int | The Y coordinate of the terrain cell. | |
z | int | The Z coordinate of the terrain cell. | |
force | WaterForce | The WaterForce value representing the water force in the cell. | |
direction | WaterDirection | The WaterDirection value representing the water flow direction. |
Returns
()
WorldToCell(position: Vector3): Vector3#
Returns the grid cell location that contains the point position.
WorldToCellPreferEmpty(position: Vector3): Vector3#
Returns the grid cell location that contains the point position,
preferring empty grid cells when position is on a grid edge.
WorldToCellPreferSolid(position: Vector3): Vector3#
Returns the grid cell location that contains the point position, preferring non-empty grid cells when position is on a grid edge.
WriteVoxelChannels(region: Region3, resolution: float, channels: Dictionary): ()#
CustomLuaState
Sets a region of terrain using a dictionary of per-channel voxel data, the
inverse of ReadVoxelChannels(). The
channels dictionary maps channel ID strings (SolidMaterial,
SolidOccupancy, and/or LiquidOccupancy) to their respective 3D data
arrays. You may write one or more channels in a single call. The region
must be aligned to the voxel grid, resolution must be 4, and the
region cannot exceed 4,194,304 voxels.
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3 | Target region to write to. Must be aligned to the voxel grid. Will throw an error if region is too large; limit is currently 4194304 voxels³. | |
resolution | float | Voxel resolution. Must be 4. | |
channels | Dictionary | Dictionary of voxel data similar to the return value of
|
Returns
()
WriteVoxels(region: Region3, resolution: float, materials: Array, occupancy: Array): ()#
CustomLuaState
Sets a region of smooth terrain from two 3D arrays: materials (an array
of Material values) and occupancy (an array of numbers between
0 and 1). Both arrays must have dimensions that exactly match the
target region in voxels. The region must be aligned to the voxel grid,
resolution must be 4, and the region cannot exceed 4,194,304 voxels.
For more granular channel control, see
WriteVoxelChannels().
| Name | Type | Default | Description |
|---|---|---|---|
region | Region3 | Target region to write to. Must be aligned to the voxel grid. Will throw an error if region is too large. | |
resolution | float | Voxel resolution. Must be 4. | |
materials | Array | 3D array of Material. Dimensions must exactly match the size of
the target region in voxels. | |
occupancy | Array | 3D array of voxel occupancies (number between 0 and 1). Dimensions
must exactly match the size of the target region in voxels. |
Returns
()
Inherited members#
Inherited from BasePart 106
Properties (69)
Anchored, AssemblyAngularVelocity, AssemblyCenterOfMass, AssemblyLinearVelocity, AssemblyMass, AssemblyRootPart, AudioCanCollide, BackParamA, BackParamB, BackSurface, BackSurfaceInput, BottomParamA, BottomParamB, BottomSurface, BottomSurfaceInput, BrickColor, brickColor, CanCollide, CanQuery, CanTouch, CastShadow, CenterOfMass, CFrame, CollisionGroup, CollisionGroupId, Color, CurrentPhysicalProperties, CustomPhysicalProperties, Elasticity, EnableFluidForces, ExtentsCFrame, ExtentsSize, Friction, FrontParamA, FrontParamB, FrontSurface, FrontSurfaceInput, LeftParamA, LeftParamB, LeftSurface, LeftSurfaceInput, LocalTransparencyModifier, Locked, Mass, Massless, Material, MaterialVariant, Orientation, PivotOffset, Position, ReceiveAge, Reflectance, ResizeableFaces, ResizeIncrement, RightParamA, RightParamB, RightSurface, RightSurfaceInput, RootPriority, Rotation, RotVelocity, Size, SpecificGravity, TopParamA, TopParamB, TopSurface, TopSurfaceInput, Transparency, Velocity
Methods (32)
AngularAccelerationToTorque, ApplyAngularImpulse, ApplyImpulse, ApplyImpulseAtPosition, BindToCollisionSummaries, BreakJoints, breakJoints, CanCollideWith, CanSetNetworkOwnership, GetClosestPointOnSurface, GetConnectedParts, GetJoints, GetMass, getMass, GetNetworkOwner, GetNetworkOwnershipAuto, GetNoCollisionConstraints, GetRenderCFrame, GetRootPart, GetTouchingParts, GetVelocityAtPosition, IntersectAsync, IsGrounded, MakeJoints, makeJoints, Resize, resize, SetNetworkOwner, SetNetworkOwnershipAuto, SubtractAsync, TorqueToAngularAcceleration, UnionAsync
Events (5)
LocalSimulationTouched, OutfitChanged, StoppedTouching, Touched, TouchEnded
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild