API ReferenceGE Extensionscore
Core Terrain
Provides terrain queries: height, normal, and smooth normal lookups.
Provides terrain queries: height, normal, and smooth normal lookups.
Overview
Extension: core_terrain - Simple utility that caches the active TerrainBlock and exposes height/normal queries. Automatically finds the first TerrainBlock in the scene if none is cached.
Public Functions
| Function | Returns | Description |
|---|---|---|
M.getTerrain() | TerrainBlock | Returns the cached (or first found) TerrainBlock object |
M.getTerrainHeight(point) | number | Returns terrain height at the given point |
M.getTerrainNormal(point) | vec3 | Returns terrain surface normal at the point |
M.getTerrainSmoothNormal(point) | vec3 | Returns interpolated smooth normal at the point |
Usage Examples
-- Get terrain height at a position
local height = core_terrain.getTerrainHeight(vec3(100, 200, 0))
-- Get normal for slope calculations
local normal = core_terrain.getTerrainNormal(playerPos)
local steepness = math.acos(normal:dot(vec3(0, 0, 1)))
-- Access raw TerrainBlock object
local tb = core_terrain.getTerrain()
if tb then
log('I', '', 'Terrain found: ' .. tostring(tb:getName()))
endImplementation Notes
- The TerrainBlock is found via
scenetree.findClassObjects("TerrainBlock")and cached by ID. - If the cached ID becomes invalid (level change), it auto-discovers the new terrain.
- Returns
nilif no terrain exists in the scene.
See Also
- Globals -
scenetreescene graph queries