Quote of the Day: “We’re almost there” -Alex
Music of the Day: Went full thrash metal today. Listened to the entirety of Hardwired to Self-Destruct (Metallica). This has become a recurring theme when working on Timmy. I Have become one of those guys that sits there with earbuds headbanging and I’m not sure how I feel about it.
I began today by working with Alex on the formation targeting behavior. Basically we re-wrote much of my original code to work with what he has now created. I hadn’t done anything wrong in mine, it was just a complicated situation because my code depended so heavily on his and vice-versa. With his main chunk now completed we were able to return to my code and basically tie everything together. We got it most of the way finished before hitting some snags with syntax and making sure that everything is passed correctly between scripts. Basically we need to select an object that’s buried deep within the hierarchy and pass it around between 3-4 scripts, then interact with it multiple times to spawn enemies and then have them move the correct way.
Alex was only here for a couple of hours though, and so I went back to working on Timmy (no longer the Destroyer of Average-Sized Cities. At least this version isn’t. Yet). I spent the day trying to get the gummy shot to work. I changed out the projectiles correctly, made sure the boss and the shot were spawning in the correct spot, and then ran into problems. I couldn’t get the shot to actually…well… shoot. All it would do is spawn above the boss’ head and then drop to the ground. Very anticlimactic. So I went through the obvious solutions. First off I found that the calculated velocity was always 0, because I never passed a target into the script (It’s a new one that replaced the one I wrote, so I’m not familiar with it). So I fixed that. Then I noticed that in the distance calculations whoever had made this new one had accidentally calculated the distance between the boss and the player by saying “distanceX = target.position.x – target.position.x” If you can’t spot the problem, that’s basically saying “b = a-a,” which tends to equal 0… always. So I changed that. Still no luck. So I started to mess with kinematics and gravity, to see if some weird interaction was causing the issue. Again, no dice. Then I noticed something. Here, see if you can see it:
No? Yeah I didn’t think you would. Took me almost 10 minutes to spot it, and I’m the guy who uses Unity every day. Look at the bottom of the picture. See that orange glob? That’s the projectile. Now look in the top right. See that mass of blue and green lines? That would be the projectile’s rigidbody and collider(s). Before I tell you why that’s a problem, here’s what those last two words mean: a rigidbody is the thing attached to an object that handles all physics interactions. When you add a force to an object, it’s the rigidbody that calculates out it’s behavior and executes it. A collider is basically a zone around an object that interacts with other stuff. I think I’ve mentioned them before, but basically that’s what handles interactions between multiple objects. So back to the problem at hand: the shot not shooting. Hopefully I’ve described it well enough that you can see where this is going.
The rigidbody and colliders, the things that interact with physics, are actually doing exactly what they’re told. In that picture I think I gave them a velocity of 100 m/s in the x and y directions, so they shot off pretty fast. However, the actual object is just falling. Now, this is another of my favorite types of problems: the “I know exactly what’s happening but no clue why” problems. So I will have to mull it over this afternoon and try some stuff out tomorrow morning. Now I’ve gotta get out of here, but I’m glad that I at least figured out the issue.
If you’ve made it this far, congrats! Buy me Metallica tickets. There is no subliminal message in that weird space over there. None at all.