Custom Terrain Provider
When physics is disabled, Altruist's character controller uses ITerrainProvider for ground detection, walkability, and slope limits. Implement it to feed your game's terrain data.
Implement ITerrainProvider
[Service(typeof(ITerrainProvider))]
public class MyTerrainProvider : ITerrainProvider
{
private readonly byte[,] _grid;
private readonly float _cellSize;
public MyTerrainProvider(/* inject your data source */)
{
_cellSize = 100f;
_grid = LoadWalkabilityGrid();
}
public bool IsWalkable(float x, float y, float z)
{
int cx = (int)(x / _cellSize);
int cy = (int)(y / _cellSize);
if (cx < 0 || cy < 0) return false;
if (cx >= _grid.GetLength(1) || cy >= _grid.GetLength(0)) return false;
return _grid[cy, cx] == 0;
}
public float GetHeight(float x, float z)
{
return 0f; // Flat terrain, or return heightmap elevation
}
public Vector3 GetNormal(float x, float z)
{
return Vector3.UnitY; // Flat, or compute from heightmap gradient
}
}
| Method | Used For |
|---|---|
IsWalkable | Block movement on unwalkable cells |
GetHeight | Ground detection and gravity |
GetNormal | Slope detection and slide direction |
Note:
ITerrainProvider is optional — the heightmap provider works without it (assumes flat terrain at Y=0). See Terrain & Heightmaps for the full terrain system and elevation examples.