1 Game a Week – Week 6

This weeks game went quite well! I was able to implement a game mechanic that I’d previously thought of as being quite complex: displaying the future positions of a physics object. In this case, I display the orbital trajectory of the spacecraft that the player is controlling. But I’m getting ahead of myself, I should start at the beginning of the week.

At the start of the week I had no idea what I was going to make. I spent some time looking through itch.io, trying to get inspiration. I decided that I wanted to make a puzzle game, and I had only watched The Matrix movies over the weekend. So I decided that I was going to make a hacker puzzle game. After a day of working on it and coming up with ideas, I had this to show for it…

GOTY????????

So, I realize I’m not having fun, I don’t really have a solid vision for the game, and I don’t actually want to make… whatever this is. It’s still early in the week, and thankfully (or unfortunately?) at this point I’ve had enough experiences like this where I know the best thing to do is scrap the prototype and make something new. No Sunk-Cost Fallacy over here.

I then decide to look through Adriel Wallick’s 1 Game a Week blog for some inspiration. Her blog and this GDC talk by her was recommended to me by Rami Ismael (@tha_rami), and is what inspired me to start making a game a week in the first place!

One game that stood out to me was her game on Week 45 (I don’t think I’ll be doing 1 Game a Week for that long!) – I liked the idea of making a space game using gravity around planets, and the trails that Adriel added to her game looked really cool. I also tried (and failed) to make a gravity based game last year, so I decided I’d give it another shot. I then thought about one of my favourite games ever: Kerbal Space Program.

In KSP, when you are orbiting a planet you can see your future trajectory. I felt that it would be cool to make a super stripped down version of this mechanic, where you have a ship in 2D, and you need to perform orbital maneuvers to enter a specific orbit.

KSPOrbits
Orbital mechanics in KSP. Found on: studiosity.com, Source: KSP Forums

So I started making the new game in the same codebase as the last one, because I had to get the game done before the end of Friday. I first setup the code to apply gravity to objects in the scene. That was very simple to do, I just implemented the formula I found here and implemented it in code like this:

public Vector2 CalculateGravity(Vector2 otherPosition)
{
    Vector2 dir = ((Vector2)transform.position - otherPosition).normalized;

    float distanceToSurface = Vector2.Distance(transform.position, otherPosition) - m_radius;

    float gravity = m_surfaceGravity * Mathf.Pow(1 + distanceToSurface, -2);

    return dir * gravity;
}

The hard part was actually adding in the orbital prediction itself. I thought of a few ways to do it, but it turns out that you can now create separate Physics scenes in Unity. This is great, because I can create a new Physics scene, copy over the objects I want to get the trajectories from, run the simulation on the scene and then track the positions of the objects over each step. It took me about a day (and a lot of hacky code) to get it working since I’d never used this Unity feature before, but I got it working in the end! Unfortunately the code was a total mess, but it worked for the purposes of just getting this game done.

An issue with the orbit prediction feature that was a nightmare to debug

I then had the great idea of adding in an editor function where I can place objects in the scene and then see their orbital trajectory without going into Play Mode. I spent way too long on this and ran into some walls. One of which was the fact that you apparently can’t create Physics scenes in Edit Mode, which meant I had to hack together some solution to prevent existing objects from being simulated. I even asked for help on Twitter, but unfortunately nobody seemed to know the answer…

The plan was that by adding this editor feature, I’d be able to build and iterate on levels more quickly. I once again remembered my own warning with the Sunk-Cost Fallacy, and abandoned the feature. I then added in the asteroids, the bullets, and then the Delta-V and Ammunition systems. Stuck together some basic levels, and got the game finished just before midnight on Friday. I actually finished the game on Friday for once! 🥳

Gameplay of the final game!

What went well

  • I was able to finish on Friday for once! (and played Deltarune over the weekend!)
  • I made a game that I thought was fun to play, and has potential.
  • I learned how to use Unity’s Physics Scene feature to make predictions.
  • I got better at writing “quick code” to get features out for prototypes

What could have gone better

  • I could have spent way less time trying to add the unnecessary editor feature.
  • I could have had a game idea that I wanted to make ready to go on Monday.
  • I would have liked to add sound effects or music, but ran out of time.
  • I would have liked to write this post-mortem on Friday, instead of Sunday night.
  • More levels would have been nice too, but once again I ran out of time.

What I learned

  • I learned more about Unity’s physics system and how it can be leveraged to make certain game mechanics.
  • I learned how fast I can code features for a short game by cutting programming best practices. (But I still know how to use best practices for “real projects”!)
  • I learned how important it is to work on a project I’m excited about, for my motivation and ability to design the game as I go

Summary

Overall, this is my favourite game so far! I’m really happy that I was able to add the orbit trajectory mechanic as I enjoyed figuring out how to implement it, as the solution isn’t immediately obvious.

Not many people have played the game as of writing this, and I haven’t really gotten any feedback. I have some ideas on how I’d improve the game to make a full version, and if enough people like it, I’d definitely spend a few months making a full game.

As always, if you want to try out the game, the link is right here:

1 Game a Week – Week 6

Park your orbiter while avoiding space debris

Available now to play on your browser

If you wanna play around with the code, I also have a link to the GitHub repo if you click here!

2 thoughts on “1 Game a Week – Week 6

Leave a comment