Warning: Here be dragons. API is still undergoing some love.
What in the world is this? Cubed is a library for dealing with voxels in Unity.
What are voxels? Voxels are cubes used to make objects in 3 dimensional space much in the way that pixels can be used to make 2 dimensional images. Think Minecraft for a real world example.
- Get the library from here or the Asset Store (coming soon!)
- Create a game object
- Add the CubedObject behaviour to the game object
- Create Cube Definitions in the inspector and assign materials to sides (this is your palette)
- Click Pack Textures in the inspector for the CubedObject
- Give the CubedObject some data (or use the editor coming soon)
- Click Bake Cubes in the inspector for the CubedObject
placeDistance = 5f
mask = 0 # can be omitted if not coming out of a capsule collider
hit = RaycastHit()
return false unless Physics.Raycast(aimingRay, hit, placeDistance, ~mask)
worldPoint = hit.point - (aimingRay.direction * 0.001f) # need to underpenetrate a little
if hit.collider.CompareTag("cubed_cube"):
cubedObject.PlaceCubeAt(worldPoint, cube)
return true
return false
var placeDistance = 5f;
var mask = 0; // can be omitted if not coming out of a capsule collider
RaycastHit hit;
if(Physics.Raycast(aimingRay, hit, placeDistance, ~mask)) {
worldPoint = hit.point - (aimingRay.direction * 0.001f); // need to underpenetrate a little
if(hit.collider.CompareTag("cubed_cube")) {
cubedObject.PlaceCubeAt(worldPoint, cube);
return true;
}
return false;
}
distance = 5f
mask = 0 # can be omitted if not coming out of a capsule collider
hit = RaycastHit()
return null unless Physics.Raycast(ray, hit, distance, ~mask)
worldPoint = hit.point + (ray.direction * 0.1f) # need to overpenetrate a little
block = cubedObject.RemoveCubeAt(worldPoint)
cubedObject.GetChunkAt(worldPoint).Generate(cubedObject.cubeTerrain.Cubes)
BroadcastMessage("DigComplete", block, SendMessageOptions.DontRequireReceiver) unless block == null
var distance = 5f;
var mask = 0; // can be omitted if not coming out of a capsule collider
RaycastHit hit;
if(Physics.Raycast(ray, hit, distance, ~mask)) {
var worldPoint = hit.point + (ray.direction * 0.1f); // need to overpenetrate a little
var block = cubedObject.RemoveCubeAt(worldPoint);
cubedObject.GetChunkAt(worldPoint).Generate(cubedObject.cubeTerrain.Cubes);
if(block != null) {
BroadcastMessage("DigComplete", block, SendMessageOptions.DontRequireReceiver);
}
}
- Collisions
- Editor in Unity