Monday, December 3, 2012

Is This ... The "F" Word?


I've known for a while that this game was to feature players wielding musical instruments who would "shoot out sound waves", but up to now I had precious little idea what that might entail. This weekend I finally got to the place where all my player characters were moving correctly and executing a one-shot attack animation so it was time to start thinking about the projectiles.

That attack animation, as an aside, was a bit hacky, as I was unable to locate a good way to get the length of a RagePixel animation to know when to make it stop. So, I set the attack on a loop and then used a coroutine and yield statement to keep the player in the attack state for a short while after the attack button is pressed, then to snap over into an idle state. So, the attack animation plays on a loop, but the player is only ever in the attack state long enough for the animation to be visible once, which turned out to be around 0.15 seconds, just eyeballing it. This solution is fundamentally goofy and I am not proud of it, but it works.

So, a traveling sound wave... I started with a GameObject and a  Rigidbody component, so I could move the thing by applying a force. I tried scaling the Rigidbody but that appeared to be the wrong idea. I then added a Box Collider and tried scaling that, but the results weren't what I was looking for. Fianlly, I just scaled the GameObject, figuring (correctly) that the attached Box Collider would just come along for the ride. I made the whole thing into a prefab, then wrote code to instantiate a clone of the prefab at the player's "weapon socket", offset along the x and y depending on facing, every time the attack button is pressed.

When I got into the code for destroying these things, I had an idea: if they were meant to be sound waves, what if they could bounce like sound waves? The first time a "bullet" collides with another object, I reverse its' direction and send it back the other way. On the second collision, I destroy it. This means you can fling several of these things out, they will bounce back, hit one another, and cancel out.

It's still very crude, but here, suddenly, is that moment when you try an experiment in your game prototype and something interesting happens. You start to think of various level structures and objects and enemies that could react to bouncing sound waves. You wonder if the player could do this in midair, and what effect that might have. You consider variations on the basic projectile, changes in frequency, force, number of bounces. You start to think you might be looking at a game. Is this ... fun?

Let's not get ahead of ourselves.
 


No comments:

Post a Comment