Day 32- Timmy’s Ascent

Day 32- Timmy’s Ascent

Quote of the Day: The entire conversation we had about Macs vs PCs. It was very heated and amusing.

Music of the Day: Halestorm and Volbeat, along with some Def Leppard.

I came in today and sort of fiddled around with a few things before finally moving on to fixing the gummy shot. Jeremy had given me a possible solution, and with a few modifications I was able to apply it. If you remember, the issue was that I could either have a projectile that moved or exploded, but not both. The solution: have both. Just at different times. Basically, I made a copy of the projectile with all of the rigidbodies on the gummies gone, and kept the original. This way, I instantiated the one without rigidbodies to have it fly towards the target, and as soon as it came in contact with something the exploding projectile is spawned in at that same location and the original is destroyed. Worked like a charm. With that done, I went to work on Timmy’s other ability, jump smash.

If you recall from ages ago when I started on Timmy (then Timmy 2.0, Destroyer of Average-Sized Cities), his other ability was to jump up and smash down on the player if they got too close. Well, when I last left it we didn’t have an animation for it, so he just sort of snapped onto the player and did a bunch of damage. So not a lot of counter play. But going back to it, I realized that instead of waiting for someone more talented than me to make an animation, I could instead use the same projectile motion I had just finished, but on the boss itself. I could make him literally jump and squash at a target area. The code wasn’t too hard, I basically just slapped in my gummy projectile script and changed a couple of numbers to fit Timmy. And voila… kind of. Timmy did indeed jump, the issue was that he didn’t ever come down. I realized I hadn’t ticked the “Use Gravity” box on his rigidbody. With that done, I was ready to watch the majesty of a giant jumping gummy bear. But again, I ran into a problem. This time, he just fell straight through the floor.

Now, I knew why this happened. It was because Timmy was ticked as “is Kinematic,” which basically means that his rigidbody was ignoring any and all forces and collisions on it. Unity lets you do this if you want to control something exclusively by code, rather than having the possibility of other objects in your scene screw with that object. Of course, this also means that he was ignoring the well-established fact in physics that a floor tends to stop things falling. So I un-ticked that box. And lo-and-behold, another problem. Now I couldn’t change his velocity via code. Thankfully, the solution to this one come to me pretty fast. Basically, I forced Timmy to turn off his kinematics while in the air, and anytime he touched something tagged as “Floor” (or the player), it was turned back on so he didn’t fall through the floor. And boom, there you go. A high-jumping gummy bear. Last thing was to add in the code that allows enemies to rotate towards the player, and I had a complete boss.

Although Timmy was now feature-complete, there were still some things that I wanted to streamline and improve. Most of them were small texturing issues or little issues with the behavior of the projectile, but those were finished very quickly. The main one I wanted to address was with his just-finished jump smash ability. Because of the nature of the gummy projectile, I had opted to lock the angle of fire at 70 degrees, so that it could fly up and over obstacles rather than shooting right into them. It stopped the player from finding a spot on the level that could shield them. With jump smash though, I didn’t want the angle to always be that high. If it was, the player would have far more time to react and move out of the way the further from the boss they were. Instead, I wanted the angle to range between 45 and 90 degrees, depending on how far away the player was. The math for this was pretty simple, I just took the ratio of the maximum distance to the actual distance and multiplied by 45. That way, if the player was exactly as far as the max range Timmy would jump at a 45 degree angle, but as the player got closer the ratio would increase and so would the angle.

That implemented, I went to test it. And immediately ran into one of the most frustrating problems I have yet experienced. Occasionally, with no correlation to anything I could see, I would get an error saying that the velocity I gave Timmy was “{NaN, NaN, NaN}.” NaN stands for “Not a Number,” and somehow Timmy was getting 1 of those in the x, y and, z directions. This wouldn’t have been a big issue if Timmy just recalculated the velocity, but even though he did that something got screwed up and he would begin his good old routine of falling through the floor. Usually that error meant that there was a division by 0 somewhere, so I went through and checked each of the divisions individually. And none of them ever equaled 0. The only thing I knew for sure was that it was somehow caused by my angle calculation, because after I hard-coded in a value (set it to a number by force), I couldn’t get the error. Even then, I had no idea why it was happening. The error had no relationship with the distance from the boss. I had it happen very close, at maximum range, and everywhere in between. in the end I just left the angle hard coded in as 70 degrees, much to my chagrin. The code for angle calculation is still there, just deactivated.

As unhappy as I was about that though, I was very glad to have Timmy done and ready to go. Hopefully he will be implemented into the game in the near future. At this point I was ready to leave, but the aforementioned conversation about Macs vs. PCs ensued, and I stayed for almost 2 extra hours talking with everyone. It was a good time.

If you’ve made it this far, congrats! I will try and remember to post pictures of Timmy tomorrow, and potentially take a video of his abilities in action. Until then!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s