Tuesday, April 24, 2012

Recreating DemolitionFX

My goal for the evening was to recreate the bouncing beach balls and the exploding balloons for the game.  I decided to throw in my old crappy background image (I'll be replacing that eventually).  I managed to get everything done with only a couple of snafus...and a weird bug.
  As you can see in the pic on the left, my scene is set up with the 'building' set in front of my background image (just a jpg used as a texture for a rotated plane) and you can see my beach balls up above waiting to fall.
My 'beams' are simply cubes...scaled appropriately x/y/z and added one of the wood textures from the original game.  They have rigidbody physics components attached to them...and I am restricting the ability to rotate around the Y axis and limiting their movement on the X so that the game remains '2D' although it is obviously created with 3d objects.  I have attached fixed joints to each beam (just like in the original game) to give the structure some stability (including attaching the bottom beams to the concrete 'ground' and have assigned them realistic force/torque breaking points so that eventually (depending on what is happening in the scene), the stability will erode when joints start snapping.  I have not yet created the ability for the beams to 'take damage' and eventually split..but it's obviously on a to-do list.

The beach ball is a simple sphere mesh with the mass turned way down.  I added a special physics material to it to add the extra bounciness.
I have yet to constrain it's position or rotation, so they just sorta bounce all over the place wherever they want to. I had to tweak the mass and physics material a bit to make it look quasi-realistic..but that is where Unity really shines...was stupid easy to click/adjust a setting and just hit the 'play' button again.  Was amazed that a search for 'beach ball texture' generated a usable result with NO effort on my part...just dragged into the project and assigned the texture to the material associated with the ball.

The balloons were pretty easy as well.  I just went (for now because I couldn't get a free 3d studio max model of balloon to import properly) with a 'squashed' sphere mesh (just changed scale in Unity) and applied a downloaded 'latex' texture to it.  Made it's mass VERY low so that it would have no effect on anything as it was bouncing around.  Added a 'constant force' component to give it a slight 'upward' force to simulate the balloon floating up.  In the original DemolitionFX, I did something similar (except I executed this code manually every render/update cycle:

 if(c instanceof Balloon){
   c.physicsObject.applyForce(new Vec2(0,-0.000002*(physicsWorld.getGravity().y)), c.physicsObject.getPosition());

I added my 'explosion' logic to the balloon prefab (hit the space bar, generate explosive force on all objects within radius.  Worked like a charm except for an odd thing...the balloons disappear!  Now, I actually intended to do a little 'explosion' particle effect or something and have the balloons disappear anyway...but I have no idea where they are going.  I am assuming because of the stupid small mass of the balloon, that the explosive force is acting on the balloon itself and it is being rocketed into the multiverse by an explosion powerful enough to topple a wooden structure.  I'll change my explosion routine to ignore the balloon object that is generating the explosion and see what happens.

No comments:

Post a Comment