Development News!


I've been working on this project a lot since I originally started it. It's been a true joy to see it come to life! Here's some things I've added and learned along the way.

I added a star field background. For this I basically start the game and treat the whole screen as a grid.  For each square in the grid, I determine a random position and put a star there. This game operates like an endless runner, in that the background and obstacle/enemy objects move, but the camera and player don't. So to give the feeling of movement, the background slowly moves down. Once the bottom row of the grid reaches the bottom of the camera, the background spawner generates a new row of stars at the top, again randomly within the top row of squares.  Right now, these objects are instantiated and destroyed. I've considered instead just simply moving the game objects when they get to the bottom, but I haven't found a need to do that yet. It doesn't seem to be impacting performance too much, but that is an option for the future.  

Making the ship rotate when it moves horizontally. This was way trickier than I expected. I thought I could just adjust the angle of rotation around the Y-axis by 45 or -45 degrees when moving, and otherwise just keep the angle at 0 degrees rotation. It turns out that in 3D space, things aren't that simple. Instead, Quaternions are used to handle spherical rotation. Quaternions are super duper complicated, and even people who use them regularly, like game developers and smart phone developers, tend not to understand them. Fortunately, there are many member functions that are provided by the Quaternion class, so all you really have to do is learn those member functions, rather than trying to set the coordinate values directly. So instead of rotating in a unit of degrees around an axis, the spaceship is told "Your goal is to look this way, and have up be this way, move there over this amount of time," and it just... figures it out. It's black magic.

I added some enemies! Two so far, one of which is in this current build. I used what I've learned about Blender to create a UFO-looking enemy ship. It took about 5 minutes to create. I'll need to make them rotate similarly to the player ship, and will do that in a future build. And they also shoot at the player! This was more learning about 3D space, specifically, vectors. Okay, well, I already kinda knew vectors from math classes, but the Vector3 class has its own functions that really help when making a game. Basically, the enemy ship determines, where am I and where is the player? Then it draws a vector between those two points, normalizes the vector to have a distance of 1, then moves along that vector at its given speed, and periodically fires a projectile in that direction. It also has a constant downward movement to force it off the screen at some point. 

Missile impacts. These I struggled with. I wanted the missile itself to hit an object, disappear, and make an explosion sound. Right now, missiles are destroyed if they move past the top of the screen, which is great, avoiding memory leaks. I wanted to have the missile play a sound, then destroy itself, when it strikes an object. That made it so that the sound wouldn't play, though, because the gameobject was destroyed before the sound could play. So then I used an IEnumerator to wait for the length of the clip to play before destroying itself, which kind of worked, except you could still see the missile on screen, and that looked... weird. I tried various other things that didn't work, and finally decided to just move the missile just beyond the top of the screen if it hit something. The actual point where it destroys itself is a few units above the top of the screen, which is enough time for the sound to play and then the missile destroys itself when it reaches the destruction point. A bit hackey, but it works and I like it. I ended up reusing this trick for when the player's ship is destroyed as well. It's a useful thing!

Diagonal missiles. At first when I coded the missiles, they were hard coded to move "up." Then I wanted to add a diagonal missile powerup, and suddenly making them move up was bad. So I revised the missile behavior to move along a vector that points "up" relative to the missile's rotation, and things looked good. 

So, I'm learning a ton about how to do things just from this one simple project. My next task is to implement a boss battle. I'll design the boss in Blender, import it, and then give it behavior. I think it'll be a huge ship with a front shield that needs to be destroyed first, multiple gun turrets that will be shooting at the player (which are destroyable), and a "heart" that's behind the shield and maybe some armor that will be the core of the boss's health. It might even have a laser turret. That will be an interesting challenge.

Files

SpaceShooterv0.6.zip Play in browser
Dec 16, 2022

Leave a comment

Log in with itch.io to leave a comment.