Multiple Questions

Plague posted this 13 June 2019

I have written a script that is similar to exploder, which uses the “value” as health of voxels. I calculate the damage for each voxel by ((damageRadius-voxelDistance)/damageRadius)*DamageAmount. And if any voxel value is to be 0 or less than 0, I use part of the original exploder script to remove that voxel. I made a test scene to test the script (attached the script to “bullet” and “rocket” prefabs, had them shoot out of camera to mouse position(and activate the damage script on collision with the object)), and it works, but at the same time it seems to be lagging a lot. I swapped to the original exploder and re-tested it, the lag was not as bad but it was still very noticeable. So my question is, is there a way to detect “voxel” if I were to attach a sphere collider for explosion that activates on impact and only checks for voxels in the said area. Otherwise with a few voxel objects the game lags a lot even for small explosions.

Last edited 17 June 2019

Order By: Standard | Newest | Votes
GarethIW posted this 14 June 2019

There's no "easy" way to find voxels inside a sphere. You have to either iterate through the sphere or iterate through the voxels. It's probably not the actual explosion calculations that is causing frame hitches. You need to use the profiler to find out exactly which calls are taking time.

You will also probably find that if you make a build (either desktop or mobile, whatever you're targeting) that the hitches don't happen or are far less severe outside of the editor.

There's a few topics here on the forums about explosions. Here are a couple that might provide some insight for you:

I don't really have anything else to suggest other than zipping up your project and sending it to me ( I'd be happy to take a look.

Plague posted this 14 June 2019

I read all the posts on this forum after posting the question, I have found that you wrote a better bullet script that (instead of checking for every volume in the scene, explodes the voxels of the object it collides with. I haven't tested that script yet, but I think that method will be much faster than using my exploder variant (because I will have a lot of objects, most made out of voxel volumes).

I want to ask a few more questions though. I'm working on a robot-figthing game kinda like the real life "robot wars" tournaments. And I'm planning to have parts of robots, I'm planning of making multiple cases/chasises, weapons, and transmission/movement parts (wheels, robotic legs, drone like things) and I was thinking whether I should make the legs animated using voxel frames or.. should I just make them and animate them by changing their position & rotation values? If I were to animate them using the first method, how would I make it so when the robot gets hit, both frames have similar damage(instead of damaging only the active frame, would I need to iterate the script over all frames of animation?)

By the way, how did you manage to make the particle-trail effect on the rockets in your game Jarheads? And how did you manage to get glowing voxel particles? (I see in jarheads trailer that when something explodes, there are glowing yellow-ish voxel particles flying around)

Thanks for all the help in advance.

Since Unity doesn't allow collisions with concave colliders, my bullets will collide with the mesh and not the voxels, and using the said bullet script might not work even if I step by step, move the collision till it hits the voxel after hitting the said object. (Because robots will have a seperate "motherboard" inside them that other robots can damage by destroying the case/chasis first) I'm thinking, in that case, I would need to create a trigger collider that covers the entire robot, and detect when my bullets collide with that trigger, and then step by step move the bullet further till it hits voxels? Or is there a way to make unity work with concave colliders on moving objects? (rigidbody objects)

Edit: Added another question

Last edited 14 June 2019

GarethIW posted this 17 June 2019

That's a few questions! Sorry for the late reply, busy weekend.

I recently helped out a user that had an animation rig (skeletal human rig) where all the body parts had a voxel volume attached. That would definitely be the way to go here. I don't know how he made the rig or whatever, it's not my area of expertise. But it's definitely no problem to have a model made up of "parts" that you can swap out, where each part is a volume that can be exploded independently.

As you have figured out, doing damage to cell animated volumes isn't recommended because damaging across frames doesn't really make sense. I mean, it's possible to do, but Volume.Explode() only works on the current frame because it doesn't make sense to have the same explosion sphere over all of the frames.

If you have multiple volumes on a model that have the potential to overlap, then your best bet is to use the hybrid collision method that I have demonstrated on the various bullet scripts I posted. You're right though that it will only work on the first volume that is hit (i.e. the one that collides with OnCollisionEnter). So you'll need to extend it to check voxels in ALL the volumes in the model's hierarchy with each step through.

I could probably come up with a script to help with this, but the gist would be:

  1. Have a component at the parent-level of your robot gameobject. On here, you should have an array of "parts" (Volumes) that make up your robot.
  2. Have a component on each part that does the bullet collision detection (OnCollisionEnter)
  3. Use GetComponentInParent to get the parent component with the volume array
  4. On each step through the collision, check for voxels in all of the volumes in the array.

re: Jarheads - the smoke trail is just a standard particle system with a cube mesh renderer. The particles have no speed or gravity, just a set lifetime after which the size decays. The glowing is done with the bloom effect of the Unity Post-processing stack (available on the asset store). The explosion particles have a high intensity HDR colour, which causes the bloom to kick in.

Last edited 17 June 2019

Plague posted this 17 June 2019

Thank you for all the information and these amazing tools <3>

Our 137 members have posted 530 times in 129 discussions