Roblox UtilitiesDevlHub Roblox Documentation

Class

Terrain

NotCreatable
Inherits
BasePart › PVInstance › Instance › Object
Memory category
Instances

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#

DecorationbooleanEnables or disables terrain decoration.ReadSafeNotScriptable
GrassLengthfloatSpecifies the length of animated grass.ReadSafeNotScriptable
IsSmoothbooleanReturns true if the game is using the smooth terrain system.ReadSafeDeprecatedReadOnlyNotReplicated
MaterialColorsBinaryStringRepresents the editor for the Material Color feature and cannot be edited by scripts.ReadSafeNotScriptable
MaxExtentsRegion3int16Displays the boundaries of the largest possible editable region.ReadSafeReadOnlyNotReplicated
WaterColorColor3The tint of Terrain water.ReadSafe
WaterReflectancefloatControls how opaque Terrain water reflections are.ReadSafe
WaterTransparencyfloatThe transparency of Terrain water.ReadSafe
WaterWaveSizefloatSets the maximum height of Terrain water waves in studs.ReadSafe
WaterWaveSpeedfloatSets 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#

AutowedgeCellObsolete function which no longer does anything.Deprecated
AutowedgeCellsObsolete function which no longer does anything.Deprecated
CellCenterToWorldReturns the world position of the center of the terrain cell.
CellCornerToWorldReturns the position of the lower-left-forward corner of the grid cell.
ClearClears all terrain.
ConvertToSmoothTransforms the legacy terrain engine into the new terrain engine.PluginSecurity securityDeprecated
CopyRegionStores a chunk of terrain into a TerrainRegion object so it can be loaded back later.
CountCellsReturns the number of non-empty cells in the terrain.
FillBallFills a ball of smooth terrain in a given space.
FillBlockFills a block of smooth terrain with a given location, rotation, size, and material.
FillCylinderFills a cylinder of smooth terrain in a given space.
FillRegionFills a Region3 space with smooth terrain.
FillWedgeFills a wedge-shaped volume of terrain with the given Material.
GetCellReturns the closest cell material from the legacy terrain engine that matches the smooth terrain voxel specified.Deprecated
GetMaterialColorReturns current terrain material color for specified terrain material.Safe
GetWaterCellReturns true if the cell is a water cell.Deprecated
PasteRegionApplies a chunk of terrain to the Terrain object.
ReadVoxelChannelsReturns a region of terrain voxel data in table format based on the channel names.SafeCustomLuaState
ReadVoxelsReturns a certain region of smooth terrain in table format.SafeCustomLuaState
ReplaceMaterialReplaces the terrain of a material within a region with another material.
SetCellSets the occupancy and material of a specific terrain voxel.Deprecated
SetCellsSets the occupancy and material of all terrain voxels in a specific region.Deprecated
SetMaterialColorSets current terrain material color for specified terrain material.
SetWaterCellSets the specified terrain voxel's material to water and sets its occupancy to 1.Deprecated
WorldToCellReturns the grid cell location that contains the position point.
WorldToCellPreferEmptyReturns the grid cell location that contains the position point, preferring empty grid cells when position is on a grid edge.
WorldToCellPreferSolidReturns the grid cell location that contains the point position, preferring non-empty grid cells when position is on a grid edge.
WriteVoxelChannelsSets a region of terrain using a dictionary of voxel channel data.CustomLuaState
WriteVoxelsSets 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.

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell.
yintThe Y coordinate of the terrain cell.
zintThe Z coordinate of the terrain cell.
Returns
  • boolean — Always returns true; 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.

NameTypeDefaultDescription
regionRegion3int16The 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.

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell in grid space.
yintThe Y coordinate of the terrain cell in grid space.
zintThe Z coordinate of the terrain cell in grid space.
Returns
  • Vector3 — The world-space Vector3 position at the center of the specified cell.

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).

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell in grid space.
yintThe Y coordinate of the terrain cell in grid space.
zintThe Z coordinate of the terrain cell in grid space.
Returns
  • Vector3 — The world-space Vector3 position of the lower-left-forward corner of the specified cell.

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.

NameTypeDefaultDescription
regionRegion3int16The Region3int16 defining the area of terrain to copy, in cell coordinates.
Returns

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.

NameTypeDefaultDescription
centerVector3The position of the center of the terrain ball.
radiusfloatThe radius in studs of the terrain ball.
materialMaterialThe 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.

NameTypeDefaultDescription
cframeCFrameThe position and orientation of the terrain block.
sizeVector3The size in studs of the square block (both the height and width).
materialMaterialThe 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.

NameTypeDefaultDescription
cframeCFrameThe position and orientation of the terrain cylinder.
heightfloatThe height in studs of the terrain cylinder.
radiusfloatThe radius in studs of the terrain cylinder.
materialMaterialThe 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.

NameTypeDefaultDescription
regionRegion3The Region3 to fill, which must be aligned to the voxel grid.
resolutionfloatThe voxel resolution; must be exactly 4.
materialMaterialThe 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.

NameTypeDefaultDescription
cframeCFrameThe position and orientation of the wedge to fill.
sizeVector3The size of the wedge to fill.
materialMaterialThe 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.

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell.
yintThe Y coordinate of the terrain cell.
zintThe 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

Returns the current Color3 color for the specified terrain Material. This color represents the tint applied to the material's base texture. Passing Air or Water throws an error because those materials do not support custom colors.

NameTypeDefaultDescription
materialMaterialThe Material whose terrain color to retrieve.
Returns
  • Color3 — The Color3 representing the current color tint of the specified material.

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.

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell.
yintThe Y coordinate of the terrain cell.
zintThe 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.

NameTypeDefaultDescription
regionTerrainRegionThe TerrainRegion to paste, previously obtained from Terrain:CopyRegion().
cornerVector3int16The Vector3int16 cell coordinate at which to place the lower-left-forward corner of the region.
pasteEmptyCellsbooleanWhether 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.

NameTypeDefaultDescription
regionRegion3Target 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³.
resolutionfloatVoxel resolution. Must be 4.
channelIdsArrayArray 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 the channelIds input. Keys represent each channel ID with their respective value as an array of 3D data.

    • SolidMaterial — The Material material of the voxel. Note that Water is not supported anymore; instead, a voxel that contains water will have a value of LiquidOccupancy.
    • SolidOccupancy — The occupancy of the voxel's material as specified in the SolidMaterial channel. This is a value between 0 (empty) and 1 (full).
    • LiquidOccupancy — Specifies the occupancy of the Water material in a voxel as a value between 0 (no water) and 1 (full of water). If the SolidOccupancy is 1 and the SolidMaterial is not Air, this will be 0.

    The dictionary also contains a Size key 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().

NameTypeDefaultDescription
regionRegion3Target 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³.
resolutionfloatVoxel resolution. Must be 4.
Returns
  • Tuple —

    Returns raw voxel data as two 3D arrays.

    • materials - 3D array of Material from 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.

NameTypeDefaultDescription
regionRegion3The region in which the replacement operation will occur.
resolutionfloatThe resolution at which the replacement operation will take place; at the moment this must be exactly 4.
sourceMaterialMaterialThe old material that shall be replaced.
targetMaterialMaterialThe 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.

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell.
yintThe Y coordinate of the terrain cell.
zintThe Z coordinate of the terrain cell.
materialCellMaterialThe CellMaterial to set for the cell.
blockCellBlockThe CellBlock shape type for the cell.
orientationCellOrientationThe 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.

NameTypeDefaultDescription
regionRegion3int16The Region3int16 specifying the area of terrain cells to set.
materialCellMaterialThe CellMaterial to apply to all cells in the region.
blockCellBlockThe CellBlock shape type to apply to all cells in the region.
orientationCellOrientationThe 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.

NameTypeDefaultDescription
materialMaterialThe Material whose terrain color to change.
valueColor3The 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.

NameTypeDefaultDescription
xintThe X coordinate of the terrain cell.
yintThe Y coordinate of the terrain cell.
zintThe Z coordinate of the terrain cell.
forceWaterForceThe WaterForce value representing the water force in the cell.
directionWaterDirectionThe WaterDirection value representing the water flow direction.
Returns
  • ()

WorldToCell(position: Vector3): Vector3#

Returns the grid cell location that contains the point position.

NameTypeDefaultDescription
positionVector3The world-space Vector3 to convert to a cell coordinate.
Returns
  • Vector3 — A Vector3 representing the grid cell coordinates containing the given 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.

NameTypeDefaultDescription
positionVector3The world-space Vector3 to convert to a cell coordinate.
Returns
  • Vector3 — A Vector3 representing the grid cell coordinates, biased toward an empty (air) neighbor when the position lies on a cell boundary.

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.

NameTypeDefaultDescription
positionVector3The world-space Vector3 to convert to a cell coordinate.
Returns
  • Vector3 — A Vector3 representing the grid cell coordinates, biased toward a non-empty (solid) neighbor when the position lies on a cell boundary.

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.

NameTypeDefaultDescription
regionRegion3Target 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³.
resolutionfloatVoxel resolution. Must be 4.
channelsDictionary

Dictionary of voxel data similar to the return value of ReadVoxelChannels(). Keys represent each channel ID with their respective value as an array of 3D data. The dictionary can support single or multiple channel inputs.

  • SolidMaterial — The Material material of the voxel. Note that Water is not supported anymore; instead, a voxel that contains only water should be entered as SolidMaterial = Enum.Material.Air, LiquidOccupancy = x, where x is a number between 0 (exclusive) and 1 (inclusive).
  • SolidOccupancy — The occupancy of the voxel's material as specified in the SolidMaterial channel. This should be a value between 0 (empty) and 1 (full).
  • LiquidOccupancy — Specifies the occupancy of the Water material in a voxel as a value between 0 (no water) and 1 (full of water). If the SolidOccupancy is 1 and the SolidMaterial is not Air, this will be 0.
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().

NameTypeDefaultDescription
regionRegion3Target region to write to. Must be aligned to the voxel grid. Will throw an error if region is too large.
resolutionfloatVoxel resolution. Must be 4.
materialsArray3D array of Material. Dimensions must exactly match the size of the target region in voxels.
occupancyArray3D 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
Inherited from PVInstance 4
Properties (2)

Origin, Pivot Offset

Methods (2)

GetPivot, PivotTo

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed