Custom script - Ashes in the wind

capnlove posted this 03 April 2015

enter image description here

I've created a simple script which destroys PicaVoxelVolumes one Voxel at a time. Doesn't sound like much but the effect is pretty cool and extremely versatile.

Watch "Ashes in the Wind" in action on Youtube

If someone knows how to embed Youtube vids, please let me know!

Basic Logic - The script loops through all voxels in a volume, based on the Sweep direction and speed. - When a voxel is found, it is deleted (set to Inactive) and a particle is spawned in its place. - The particle is propelled in a direction specified by a Vector3.

The effect was based on the provided Destructor script, but doesn't use raycasting to achieve the effect. I don't know if it's faster but my test scene has 3 objects destroying one voxel each on every tick while maintaining a solid 60fps.

In order to achieve this effect, you need the following 2 functions

1. Note that I've added to Voxel.cs which simply returns a new Voxel(); i.e. a blank, inactive Voxel.

GetVoxelWorldPosition => This function was graciously provided by Gareth Williams and should be part of 1.2.0. It takes the X,Y,Z voxel coordinates and returns the equivalent world position. Insanely useful!

    public Vector3 GetVoxelWorldPosition(int x, int y, int z)
    Vector3 localPos = (new Vector3(x * ParentVolume.VoxelSize, y * ParentVolume.VoxelSize, z * ParentVolume.VoxelSize) + ( * (ParentVolume.VoxelSize / 2f)) );

    return transform.TransformPoint(localPos);

GetVoxelatXYZ => A bit weird but this function returns a Voxel object from a world position. The functions provided with PicaVoxel only return positions, I needed to access the voxel directly so now we can!

    public Voxel GetVoxelatXYZ(int x, int y, int z)
        Vector3 v = GetVoxelWorldPosition(x, y, z);
        Voxel vox = (Voxel)GetVoxelAtWorldPosition(v);

        if(vox.Equals( return;
        else return vox;        

If anyone wants the source to this, let me know!

Order By: Standard | Newest | Votes
frrrosty posted this 20 April 2015

That looks great! I'd certainly like to take a look at the source. I think I'd find it useful.

capnlove posted this 21 April 2015

Allright, frrosty, your wish is my command.

You can grab the script here :

Note that I haven't tested it with version 1.2 yet so you might need to add the appropriate functions described in the original post and you might have to tweak the script.

That being said, feel free to make this your own; I just hope you guys can learn from it!

Simply add the custom script to the object you want to dissolve and then call its ActivateEffect(); function when needed.

GarethIW posted this 22 April 2015

Great stuff Capnlove! It's been a busy month and I'm only just getting round to replying to a bunch of PicaVoxel stuff. I might have some optimisation suggestions for this, but I'll need to take a closer look. Thanks for sharing!

frrrosty posted this 28 April 2015

Thanks so much, capnlove! Very generous of you!

capnlove posted this 28 April 2015

@frrrosty : It is my pleasure! No sense in keeping algorithms secret; we can achieve much more if we share and improve each other's work. That's my philosophy anyways :)

@Gareth : No rush! Feel free to improve or even integrate it in the official repo.

capnlove posted this 02 May 2015

Like a dummy I forgot to share the Editor which allows this script to be customized -> Editor script

Last edited 03 May 2015

frrrosty posted this 03 May 2015

@capnlove That link seems to be going to a mostly blank page?

capnlove posted this 03 May 2015

:) Double Dummy Day it seems! Fixed!

Our 137 members have posted 528 times in 128 discussions