Posted by Abban on 05/07/2017
Like a lot of people one of the things I wanted to make when I first started learning game development was a platformer. And what better platformer to learn from than the greatest one ever made, Super Mario World.
One of the most iconic things about Super Mario World, the greatest platformer ever made, was the world map and I want to do something similar in our next game. So, I created a small project in Unity to help me get started and in this post I'm going to take you through it and explain how it all works. It's easier than you might think.
This project contains 4 sprites and 4 script files.
I've also included the Affinity Designer file for the sprites in case you want to make edits. Don't know what Affinity is? It's a great vector art tool, you should check it out.
The way this system works is by moving a character sprite between waypoints. Each waypoint can link to up to 4 other waypoints and can be a junction, a level, or a corner. Depending on how each waypoint is set up the character will either stop or keep moving (you want the character to stop at junctions and levels but not on corners). When the character stops on a waypoint that contains text for a scene that is passed back to the Map Manager.
I built each component as bare bones as possible, this will make it easier for you to extend it into what you need.
The Map Manager is very basic, it initialises the Character then sits waiting for player directional input. When an input event happens it passes the desired direction from it to the Character.
As an example of a callback it will also update the GUI level text when the Character stops on a level.
On each frame this script sets the camera's x and y coordinates to a target's x and y.
These are the individual items in the waypoint system. Each one has 4 variables for attaching them to other pins. When another pin is attached it will draw a line Gizmo for visualisation.
When the Character reaches a pin is set to be automatic it will try get the first attached Pin that is not the one it came from. For this reason automatic Pins should only have 2 attached Pins. They're meant for corners.
Thats pretty much it, all a Pin needs to do is provide links to its neighbours for the Character.
The Character is what moves around the map. A target Pin can be set and it will move towards that Pin at a constant rate. When it reaches the target Pin it will check to see if it's an automatic one.
If the Pin is automatic it will ask it for the next Pin to keep moving. In this way, if you want to, you can set up a chain of automatic pins to move the character along a complex route.
If the Character reaches a non automatic Pin it will stop and wait for user input before resuming. It will also let the Map Manager know that its waiting.
And that's it in a nuts hell. Something like this is really easy to extend.
For example if you wanted to transition into a smaller map like when Mario enters a cave in SMW you could create a Pin type for that and tell the Map Manager to fade to a new map either in a different scene or in another location in the same scene.
If you want to lock some levels you could add a locked boolean to the pin script and check for that when trying to move towards it.
I'll be using a version of this on our next game and I hope its a help to you too. If you have any thoughts or questions you can hit me up on Twitter.
Lastly, here's an example of us using this in our next game: