Skip to content

Class · inherits BasePart

Terrain

Official docs ↗

Terrain lets you to create dynamically morphable environments.

About Terrain

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 9

  • Decoration: booleanNotScriptableEnables or disables terrain decoration.

    Currently enables or disables animated grass on the Grass terrain material, although future modifications of this property may control additional decorative features.

  • GrassLength: floatNotScriptableSpecifies the length of animated grass.

    Specifies the length of animated grass on the Grass terrain material, assuming Decoration is enabled. Valid values are between 0.1 and 1.

  • MaterialColors: BinaryStringNotScriptableRepresents the editor for the Material Color feature and cannot be edited by scripts.

    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: Region3int16ReadOnlyNotReplicatedDisplays the boundaries of the largest possible editable region.

    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: Color3The tint of Terrain water.

    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: floatControls how opaque Terrain water reflections are.

    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: floatThe transparency of Terrain water.

    The transparency of Terrain water, on a scale of 0 (fully opaque) to 1 (fully transparent). The default value is 0.3.

  • WaterWaveSize: floatSets the maximum height of Terrain water waves in studs.

    Sets the maximum height of Terrain water waves in studs. This is currently constrained to between 0 and 1.

  • WaterWaveSpeed: floatSets how many times Terrain water waves will move up and down per minute.

    Sets how many times Terrain water waves will move up and down per minute. This is currently constrained to between 0 and 100.

Methods 21

  • CellCenterToWorld(x: int, y: int, z: int) → Vector3Returns the world position of the center of the terrain cell.

    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.

  • CellCornerToWorld(x: int, y: int, z: int) → Vector3Returns the position of the lower-left-forward corner of the grid cell.

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

  • Clear() → ()Clears all terrain.

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

  • CopyRegion(region: Region3int16) → TerrainRegionStores a chunk of terrain into a TerrainRegion object so it can be loaded back later.

    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.

  • CountCells() → intReturns the number of non-empty cells in the terrain.

    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.

  • FillBall(center: Vector3, radius: float, material: Material) → ()Fills a ball of smooth terrain in a given space.

    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.

  • FillBlock(cframe: CFrame, size: Vector3, material: Material) → ()Fills a block of smooth terrain with a given location, rotation, size, and 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.

  • FillCylinder(cframe: CFrame, height: float, radius: float, material: Material) → ()Fills a cylinder of smooth terrain in a given space.

    Fills a cylinder of smooth terrain in a given space. The space is defined using a CFrame, height, and radius.

  • FillRegion(region: Region3, resolution: float, material: Material) → ()Fills a Region3 space with smooth terrain.

    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.

  • FillWedge(cframe: CFrame, size: Vector3, material: Material) → ()Fills a wedge-shaped volume of terrain with the given 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.

  • GetMaterialColor(material: Material) → Color3Returns current terrain material color for specified terrain material.

    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.

  • PasteRegion(region: TerrainRegion, corner: Vector3int16, pasteEmptyCells: boolean) → ()Applies a chunk of terrain to the Terrain object.

    Applies a chunk of terrain to the Terrain object. Note that TerrainRegion data does not replicate between server and client.

  • ReadVoxelChannels(region: Region3, resolution: float, channelIds: Array) → DictionaryReturns a region of terrain voxel data in table format based on the channel names.

    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.

  • ReadVoxels(region: Region3, resolution: float) → TupleReturns a certain region of smooth terrain in table format.

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

  • ReplaceMaterial(region: Region3, resolution: float, sourceMaterial: Material, targetMaterial: Material) → ()Replaces the terrain of a material within a region with another 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.

  • SetMaterialColor(material: Material, value: Color3) → ()Sets current terrain material color for specified terrain material.

    Sets current terrain material color for specified terrain material. Terrain material will shift its base color toward specified color.

  • WorldToCell(position: Vector3) → Vector3Returns the grid cell location that contains the position point.

    Returns the grid cell location that contains the point position.

  • WorldToCellPreferEmpty(position: Vector3) → Vector3Returns the grid cell location that contains the position point, preferring empty grid cells when position is on a grid edge.

    Returns the grid cell location that contains the point position, preferring empty grid cells when position is on a grid edge.

  • WorldToCellPreferSolid(position: Vector3) → Vector3Returns 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) → ()Sets a region of terrain using a dictionary of voxel channel data.

    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.

  • WriteVoxels(region: Region3, resolution: float, materials: Array, occupancy: Array) → ()Sets a certain region of smooth terrain using table format.

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

Terrain also has every member of BasePart. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.