Is it possible to have a dynamic mesh collider on voxel objects?

cheesebugur101 posted this 4 weeks ago

As part of the volume gets destroyed, I would like what's underneath to be accessible to ray casting. Right now I'm able to destroy the outermost layer of voxels, but as soon as those are gone, the mesh collider doesn't allow for the exploder's raycast to reach the voxels in behind.

I'm also wondering how volume splitting was done (, and if it's possible to smash a volume into smaller volumes.

Any help is appreciated!

Order By: Standard | Newest | Votes
GarethIW posted this 4 weeks ago

I'm guessing you're using Convex mode for the meshcolliders. Concave would be the mode to use if you want the collision mesh to exactly match the voxels. However, concave meshcolliders come with restrictions, such as not playing nicely with rigidbodies. They work fine for (for example) terrain or anything that doesn't move.

If you need to use convex, then your best bet would be to use a hybrid raycast. You would first cast a ray using normal Unity physics and then when you hit a Volume object, continue stepping along the ray using Picavoxel's Volume.GetVoxelAtWorldPosition() until you either hit a voxel or reach a certain distance to stop checking.

There is an example of this in the Islands demo, take a look at the IslandsClickBoom.cs script.

The volume splitting was just an experiment and isn't part of the main PicaVoxel package because it's probably not performant enough to use in production games. Your mileage may vary, though, so feel free to give it a try:!AhdchalVsPvXnMk861F6BPKYeCbr0w

One thing it doesn't do which it probably should is destroy splits when there are no voxels left active, which would require a count of active voxels after a split takes place.

Our 330 members have posted 404 times in 96 discussions