Our game continues...

Waaaaay back in 1983, a game called Bugaboo the Flea was released for the ZX Spectrum (Ported to the Amstrad CPC as Roland in the Caves). It had a very simple mechanic that made the game easy to play, yet difficult to master: Hold the jump left or jump right button longer to jump further in the direction, whilst avoiding the nasty spikes and Pterodactyl from getting you.

After a series of successful breakthroughs with my own work, my manager challenged me to recreate the game for a mobile platform (or in the very least, drawing heavy inspiration from the game). This challenge had already been looked at by both previous work experience placements Ethan and William. However, where they used Construct 2 to create a 2D prototype I decided that it would be more befitting of my experience to use Unity3D, not only through preference but also because it can deploy to Android.

So where do I begin? Like most small first-time titles, the best place to start would be the core mechanic that the game revolves around, requiring:

  • An environment to move around in
  • A player to move around
  • A plan (because you won't get far without one!)

The first two were easy to get started with. Using the backdrop from the previous projects, I recreated the cavern in 3D:
It doesn't get more cave than that So very quickly we had an environment, a player and platforms. All the collisions are handled by the Engine. What we really need to focus on now is getting the player to move!

As a mobile game, input would be strictly reduced to nothing more than screen (mouse) inputs and somehow translating that input into specific jumps similar to those used in Bugaboo.

As Ethan quite rightly noted in his blog post we can calculate such an angle by detecting the X and Y position of the mouse when we press the mouse button down, and again when the mouse button is lifted; the difference between the two gives us an angle and a magnitude, used for direction and jump strength.

With a solid jumping mechanic in place, it was time to add the opposition. The behaviour for the pterodactyl enemy was considered to be one of the larger milestones for the game due to the complexity involved, but with a bit of tactful planning even that could be completed without any major issues.

The previous approach both Ethan and William had appeared to take was to have the enemy move once the player was in sight, then to fly directly to them; often hitting a wall in the process and getting stuck.

A more modern alternative for NPC navigation is to use what's known as a "nodegraph", a set of connected nodes that inform the NPC of the paths they can take.

There were certain other rules that would need to be implemented with the nodegraph for this project:

  • Path decisions: Should the enemy have a preferred path it likes to take, take a shorter path to the player or just randomly pick a direction?
  • Doubling back on itself: As the enemy is flying, the likelihood of it doing a full 180 and going back the way it came should be very small in comparison to the other paths available.
  • Approaching the player: if the player isn't close enough to a path or node, what then?

Again, the answer doesn't need to be overly complex. The nodegraph consists of a Unity GameObject at each node, each with the same script that allows for a dynamically sizable list of other connected nodes and a variable for "bias". This bias variable allows us to assign a greater probability of being selected when using the Random.Range() method in Unity (picking a random value from 0 to the total bias of all paths).

We can reduce the likelihood of backtracking by artificially lowering the path to the previous node, but not entirely (for instance if the enemy moves to the dead end node in the top left where it starts, the option to double back is open to it).

As this project is still within its prototype stages, much improvement is to be expected in future development:

  • Switching from a plain environment to one made with a mesh
  • Mesh models for the enemy and player
  • Sound effects!
  • Better enemy behaviour - spot the players last seen location and move to its nearest node to search for the player
  • Scenematic cutscene showing the player falling into the cave
  • Deployment to android devices