Dev » Lua API » terrain
← Back to all classes

terrain

World & Entities 8 Methods

terrain

The terrain static module provides methods to query and manipulate voxel/heightmap terrain at any world position.

Overview

Methods (8)

Method Signature Returns Summary
terrain.getControl(position) number Gets the terrain control map pixel value.
terrain.getDominantTexture(position) number Gets the dominant terrain texture layer index at position.
terrain.getHeight(position) number Gets terrain elevation height at position.
terrain.getNormal(position) vector3 Gets the terrain surface normal vector.
terrain.getSteepness(position) number Gets the steepness of the terrain at position.
terrain.getSurfacePosition(position) vector3 Calculates the 3D surface point on ground.
terrain.getSurfaceRotation(position) vector3 Calculates Euler rotation aligned to terrain slope.
terrain.setHeight(position, height) void Sets terrain surface height at the given coordinate.

Detailed Reference

# getControl METHOD
terrain.getControl(position)
Gets the terrain control map pixel value.
Parameters
ParameterTypeDefaultDescription
positionvector3

Query coordinates.

Returns
number

Control map raw uint value.

Description

Reads raw splatmap / control data used for terrain blending.

# getDominantTexture METHOD
terrain.getDominantTexture(position)
Gets the dominant terrain texture layer index at position.
Parameters
ParameterTypeDefaultDescription
positionvector3

Query coordinates.

Returns
number

Texture layer index.

Description

Returns the texture layer index with the highest weight (e.g. sand, grass, rock).

# getHeight METHOD
terrain.getHeight(position)
Gets terrain elevation height at position.
Parameters
ParameterTypeDefaultDescription
positionvector3

Horizontal 3D coordinates.

Returns
number

Terrain height (Y value).

Description

Returns the terrain Y elevation at the given X/Z coordinates.

# getNormal METHOD
terrain.getNormal(position)
Gets the terrain surface normal vector.
Parameters
ParameterTypeDefaultDescription
positionvector3

Query coordinates.

Returns
vector3

Surface normal unit vector.

Description

Returns the normalized 3D normal perpendicular to the terrain at position.

# getSteepness METHOD
terrain.getSteepness(position)
Gets the steepness of the terrain at position.
Parameters
ParameterTypeDefaultDescription
positionvector3

Query coordinates.

Returns
number

Normalized steepness factor (0.0 flat to 1.0 vertical).

Description

Returns a normalized slope factor.

# getSurfacePosition METHOD
terrain.getSurfacePosition(position)
Calculates the 3D surface point on ground.
Parameters
ParameterTypeDefaultDescription
positionvector3

Query coordinates.

Returns
vector3

Exact point on ground surface.

Description

Returns a vector3 with the terrain height as the Y coordinate.

# getSurfaceRotation METHOD
terrain.getSurfaceRotation(position)
Calculates Euler rotation aligned to terrain slope.
Parameters
ParameterTypeDefaultDescription
positionvector3

Query coordinates.

Returns
vector3

Euler rotation in degrees aligned with slope.

Description

Computes the pitch and roll angles matching the ground normal at position.

# setHeight METHOD
terrain.setHeight(position, height)
Sets terrain surface height at the given coordinate.
Parameters
ParameterTypeDefaultDescription
positionvector3

Horizontal 3D coordinates.

heightnumber

New height value in world units.

Returns
None (void)
Description

Modifies the terrain elevation at position.