Environment & Terrain
advanced scriptingVoxel Play 3 · Scripting / API
VoxelPlayEnvironment. Access via VoxelPlayEnvironment.instance.
Raycasting
bool RayCast(Rayd ray, out VoxelHitInfo hitInfo, float maxDistance = 0, int minOpaque = 0, ColliderTypes colliderTypes = ColliderTypes.AnyCollider, int layerMask = -1, bool createChunksIfNeeded = false)Casts a ray through the voxel world and returns hit information. Uses voxel-level precision (not Unity physics). Returns true if a voxel was hit.
- ray
- Double-precision ray (origin + direction).
- hitInfo
- Output: hit information including chunk, voxel index, point, and normal.
- maxDistance
- Maximum ray distance. 0 = unlimited.
- minOpaque
- Minimum opacity to consider a hit (0 = hit transparent voxels too).
- colliderTypes
- Filter which collider types to detect.
bool RayCast(Vector3d origin, Vector3 direction, out VoxelHitInfo hitInfo, float maxDistance = 0, int minOpaque = 0, ColliderTypes colliderTypes = ColliderTypes.AnyCollider, int layerMask = -1, bool createChunksIfNeeded = false)Casts a ray from a world position in the specified direction.
Damage Raycasts
bool RayHit(Rayd ray, int damage, float maxDistance = 0, int damageRadius = 1)Casts a ray and applies damage to the first voxel hit. Returns true if a voxel was destroyed.
bool RayHit(Rayd ray, int damage, out VoxelHitInfo hitInfo, float maxDistance = 0, int damageRadius = 1)Damage raycast with hit information output.
bool RayHit(Vector3d origin, Vector3 direction, int damage, float maxDistance = 0, int damageRadius = 1)Damage raycast from a world position.
bool RayHit(Vector3d origin, Vector3 direction, int damage, out VoxelHitInfo hitInfo, float maxDistance = 0, int damageRadius = 1, int layerMask = -1)Full damage raycast with all options.
- damageRadius
- Radius of damage around the hit point. 1 = single voxel.
Line Casting
int LineCast(Vector3d startPosition, Vector3d endPosition, VoxelIndex[] indices, int startIndex = 0, int minOpaque = 0)Gets all voxels along a line between two points. Returns the number of voxels found. The output array must be pre-allocated.
int LineCast(Vector3d startPosition, Vector3d endPosition, VoxelChunk[] chunks, int startIndex = 0)Gets all chunks crossed by a line between two points.
Terrain Height
float GetHeight(Vector3d position)Returns the Y coordinate of the highest voxel below the given position. Useful for placing objects on the surface.
float GetTopMostHeight(Vector3d position, float maxDistance = 128)Returns the Y coordinate of the highest voxel above the given position within the search distance.
float GetTerrainHeight(Vector3d position, bool includeWater = false)Returns the terrain height based on the heightmap (not actual voxels). Faster than GetHeight but less precise after modifications.
HeightMapInfo GetTerrainInfo(Vector3d position)Returns terrain metadata including height, moisture, and biome information for the given position.
HeightMapInfo GetTerrainInfo(double x, double z)Returns terrain metadata by XZ coordinates.
Biomes
BiomeDefinition GetBiome(float altitude, float moisture)Returns the biome definition for the given altitude and moisture values.
BiomeDefinition GetBiome(Vector3d position)Returns the biome at the specified world position.
Water
bool IsWaterAtPosition(Vector3d position)Returns true if there is water at the given position.
bool IsWaterAtPosition(double x, double z)Checks for water at XZ coordinates (uses terrain data, not voxel data).
float GetWaterDepth(Vector3d position)Returns the water depth at the given position. Returns 0 if no water.
void AddWaterFlood(Vector3d position, VoxelDefinition waterVoxel, int lifeTime = 24)Creates a water source that floods outward from the given position.
- waterVoxel
- The water voxel definition to use for flooding.
- lifeTime
- Number of flood propagation steps before the source expires.
bool enableWaterFloodPublic field. Enables or disables water spreading/flooding simulation.
Lighting
float GetVoxelLight(Vector3d position)Returns the light level at the given position as a 0-1 value (combines sun and torch light).
float GetVoxelLight(Vector3d position, out VoxelChunk chunk, out int voxelIndex)Returns the light level along with chunk and voxel index references.
int GetVoxelLightPacked(Vector3d position)Returns a packed integer containing both sun and torch light values for advanced light calculations.
int GetVoxelLightPacked(Vector3d position, out VoxelChunk chunk, out int voxelIndex)Returns packed light with chunk and index references.
void UpdateLights()Forces an immediate recalculation of all light values across all chunks.
Time of Day
void SetTimeOfDay(float time, float azimuth = -1)Sets the game time. The value ranges from 0 to 1, representing a full 24-hour cycle (0 = midnight, 0.5 = noon).
- azimuth
- Optional sun azimuth angle. -1 = use default.
void SetSunRotation(Quaternion rotation)Sets the sun's rotation directly. Overrides the time-of-day system for custom lighting setups.
Textures
void ReloadTextures()Forces all voxel textures to be reloaded. Call after modifying voxel definition textures at runtime.
Runtime Properties
bool enableDetailGeneratorsPublic field. Enables or disables detail generators (trees, vegetation, ore deposits).
byte noLightValue { get; }Default light value for empty/dark voxels.
GameObject playerGameObject { get; }Returns the player's GameObject.
bool cameraHasMoved { get; }Returns true if the camera has moved since the last frame.
bool captureEventsPublic field. Enables or disables event dispatching. Set to false to suppress all events temporarily.
Statistics (Read-Only)
int voxelsCreatedCountTotal number of voxels created since initialization.
int treesInCreationQueueCountNumber of trees waiting to be created.
int treesCreatedTotal trees created since initialization.
int vegetationInCreationQueueCountNumber of vegetation instances waiting to be created.
int vegetationCreatedTotal vegetation instances created.
Suggest an improvement
Help us improve this documentation page.