Showing posts with label Explosion. Show all posts
Showing posts with label Explosion. Show all posts

Friday, May 2, 2014

Update 33: More Refined Destruction

After refining the decay code, I went to work combining it with the destruction code. As I mentioned before, the idea was to dynamically explode my object and then use the decay to clean up the exploded blocks. This would double as a garbage collector and visually clean up the screen after the object had been destroyed. I also spent a lot of extra time making sure it would work with objects of different sizes and objects rotated. Subtle, but challenging to get right in all places. Below is a series of screenshots showing the current explosions and results. The biggest trouble I had was creating an object in the middle of my explosion with the right force. I'm very happy with the results here. You'll also notice in the during screenshots that 30% of my cubes are applied the same explosion texture as the center of the explosion. I found that this helped with performance and the explosion animation.

Square before:

Square during:

Square after:

Tank before:

Tank during:

Tank after:

Friday, September 20, 2013

Update 19: Alpha 1.55 - Targeting and More Dynamic Explosions

Continuing with my momentum, I've implemented a new mechanic based on some feedback I received. When the camera zooms in behind a player to shoot, it now shows a partially-transparent-targeting-indicator. It's now a little more obvious who you are aiming at, especially when there are a cluster of enemies close together.




I've also been working at creating more dynamic explosions. In Version 1.45 I had created a prefab that contained little blocks. When the prefab was hit, I'd basically pull down the wall and let the little blocks explode. While effective, I found that when I scaled up from a 10x10 level to a larger 30x30 tile level, that the prefabs and all those little blocks really hit the frame rate pretty hard. 

To solve this, I wrote a little class that divides the parent object into a series of smaller cubes - created when I need them. Then instead of a million little cubes buried in my level, the cubes aren't created until they are needed.

Here is a sample before:



And after: 





Next on the list is some timing and camera improvements.



Tuesday, September 10, 2013

Update 17: Alpha 1.45 - Explosive Walls

I've been working on destructive terrain, and I decided the best way to blow up something, is to build it up first, literally brick by brick. As my current walls were just a (1,0.5,0.1) sized wall, I figured I should build it with 50 individual bricks into a prefab. Then when I apply force to it, it will spray across the screen in 50 pieces not one!




My first hurtle was that when I applied the rigid body property to all of the bricks, the wall tended to wobble like jelly (Jello for you Americans). I was able to solve this by not applying my RigidBody component (to enable physics) until the explosive force was applied. It actually turned out to be easier to apply this component to items in the blast radius rather than every single item on the screen. It's probably cheaper, (resource wise), too!

Next it was time to stack a few of these prefabs on top of each other, and then apply an explosive force to a random point in front of the wall... the resultant explosion was... unexpected. I'm still not sure why the explosion is along the z plane...




Moving on, applying the new prefab to my test level, it gives a far more satisfying burst across the screen when I throw grenades.




There is no download for this, I'm still adding some the next feature... which is visible in that last screenshot...

Wednesday, September 4, 2013

Update 16: Alpha 1.4: Throwing

In the last few Alpha releases, I've been focusing on stabilizing the camera and shooting mechanics. I feel much better about how it all looks, especially the camera movement, with all bugs around the camera now addressed.

Although I have a few timing issues with the shooting still to solve, I've moved on to the next type of attack, throwing grenades. I started by working through the physics and showing the trajectory. 

With the help of two very important links:

  1. Some excellent theory from the Castle Story: http://www.sauropodstudio.com/dev-diary-number-eight/
  2. A script to draw the line from Unity3D wiki: http://wiki.unity3d.com/index.php/Trajectory_Simulation

Using this, I was able to calculate the distance to the target, based on a fixed angle of 45 degrees: this meant that I can throw my grenade in a nice parabolic curve towards the target. 

Here are two screen shots showing this in action in my test level, with the red line replaced by a trail of smoke: 

Just before the grenade hits...


Just after the grenade hits...


When my grenade collides against my target, it 'explodes'. At the moment it's just an expanding red sphere - particle effects to come later. I use the Physics.OverlapSphere() function to look for items within a certain radius:

Collider[] hits = Physics.OverlapSphere(myProjectile.transform.position, explosionRadius);


If any of my collider hits are a player, I deal damage, but if it's destructible terrain, I use the AddExplosionForce() function like this:

//If destructible terrain was hit, destroy it
if (hit.collider.tag == "DestructibleTerrain") 
{
    //Add Rigidbody to terrain/wall
    hit.transform.gameObject.AddComponent<Rigidbody>();
    
    //Add explosive force at the point of the projectile impact
    hit.transform.rigidbody.AddExplosionForce(explosionForce, myProjectile.transform.position, explosionRadius);
}

This has two effects: it removes the destructible terrain from the explosion area, and it propels the same terrain across the map, which I think is pretty cool...

You can download version Alpha 1.4 here: http://www.samsmithnz.com/content/tbe/tbe_alpha1.4.zip.