Chapter 6. Wow. Now that was a doozy. Tons of code, a new model, rigidbodies, hurling things, instantiating more things. Just wow. Lots to take in.
We started off with rigidbodies. Rigidbodies are objects that Unity’s Nvidia PhyzX will run physics simulations on, in our case a coconut. We make this coconut exactly 1 kilogram (2.2 pounds for the yanks) and shape it into an elongated oval. Then we get to the fun part, HURLING things! We build a gameObject that’ll spawn a new coconut everytime you throw one, just so you’re never empty handed. We check the players input and everything he lets UP on the leftmouse (or left ctrl) the coconut will be thrown forward with a force of 25.
You’ll have to bear with me, there is a lot of code in this chapter, so a lot of oversimplification.
Now, obviously we can’t just let the player throw everything around everywhere (like in the hilarious, HILARIOUS earlier demo) because it bogs down the machine to be running 250 different coconuts physics. So alas, we both limit WHERE the player can throw, and how long a coconut may exist in this world. We do so by establishing that unless the playercollider is touching the mat portion of the minigame platform, he cannot throw. To destroy the coconuts we simply use a script that sets them to destroy after 5 seconds. Poor things.
So now we add the actual game play. A target shooting game to win one of our batteries. We make some targets, and set them to fall over if they come into collision with a coconut object. When that happens they’re triggered to play their falldown animation, and increment a hidden counter to see if all 3 targets are over. After a few seconds they pop back up, decrease the counter, and so on and so on. When the hidden counter reaches 3 (aka, all 3 targets are knocked over) then we go ahead and spawn a fantastic battery.
Like I said, it’s a very technical chapter. Hard to put into plain english. I can only hope you gathered half of what this chapter entailed from that summary. As usual, questions can be asked in the comments, on my twitter, or at my email.
Here’s the demo:
p.s. I also figured out how to convert .X models to .FBX, that’s what the other building is. Also started just cel shading a few objects for kicks. Also, no idea why most things are set up as fullbright, I blame the sun as being too strong but I need to set the settings weird just to get the Unity Editor to run on my ancient video card, so bear with me.










