C# Tinkering

Throughout the trimester whenever I had excess free time, I tinkered around with some coding.  Unfortunately I struggle with coding, it’s something I wish I could do so much better because the ability to code well is so powerful these days and it’s only going to get more powerful as time passes.  So with this excess free time I decided that I wanted to work on scripting animations and also make an attempt at an old euler angle problem I couldn’t solve in my previous trimester.

Firstly, the euler angle.  This was an issue that caused me no small amount of headache in the last trimester.  I literally wasted 3 entire days trying to figure this incy wincy problem.  It’s always the problems you think will be so easy to solve that cause the most drama.  For this top down game all I wanted to do was have the spaceship rotate until it was facing the right direction which was determined by controller inputs.  So for example if you hold down the ‘left’ button the ship would rotate until it was facing left, that’s it.  Simple right?.  Well that’s what I thought until I threw my computer through the window in a rage.  This is a common side effect I have when code doesn’t work when it bloody well should!!  When I first attempted this problem, I could get it to rotate in every which way except the way I wanted.  No matter what I did it would just never work.  This time around, I have a little more experience with scripting and I realized that I had to get the rotation into a single vector variable.  Before I was assigning each button its own rotation which ended up always conflicting with the other buttons.  Once I had this variable I put it into a Mathf.MoveTowardsAngle function and bobs your uncle, it worked.  Check out the image below for specifics:

Screenshot 2015-05-04 21.55.13

After that small victory with euler angles, I decided to tinker with scripting animations.  So avatar movement animations, model animations from imported assets and also to create my own animations from static prefabs.  I’m not going to lie, it was actually pretty straight forward.  For the input animations for the player’s avatar it was simply assigning the appropriate animation to each input key and when that animation was playing turn the other animations off.  For the zombie animations however it was a bit more involved.  Because I was spawning in multiple zombies I didn’t want them all to use the same animation now at the same time, so I threw all the animations into an array, created a ‘Random.Range’ int variable and when the zombie was spawned it would pull it’s animation component and then pick a random animation to play on loop.  Check out the below image for details:

Screenshot 2015-05-04 22.04.57

And to see all this glorious scripting in action, watch the 40 second video below: