classic sonic, editable
(WIP & Unreleased)
The original games use a grid of Solid Tiles to build up terrain. Sonic Studio, on the other hand, uses free flowing vector lines to build up terrain. One is more restrictive than the other... but that one is easier to deal with than the other. Tile vs Vector Collision Setups I'm going to try and explain how both the original game's collision setup works, and how Sonic Studio's works. If you are a seasoned programmer, this post will come as no surprise, but I mainly want to express the challenges faced in Sonic Studio to those who may assume how things work based on what they are used to. Such as the tiles like those in the classic games, be it in hacking tools, or other level editors like SMM. Solid Tiles (original games) Below is a sample of the Solid Tiles the original Sonic games use to build terrain. These are 16x16 height arrays. For example, the third tile shown is a full diagonal. In this diagonal, the height array values in this tile would be 1 in the first pixel column, 2 in the second column, and so on with 16 in the 16th column. In addition to the height values, they each come with pre-calculated angle values, that one being 45 degrees. In-game, these tiles are smartly combined like a jigsaw in multiple different ways to create the recognisable slopes and curves we are used to. When you use a grid to build any sort of map, collision or otherwise, the process for finding and reacting to any given tile is easy. Let's go through the process for the original game:
Then the tile can be reacted to. Minimal work needed. Vectors (Sonic Studio) Vectors are a different story. Vectors in this case just mean... lines. These lines have a starting point, and ending point, and an angle. When you are building a stage, you can create and modify terrain polygons, as you would a shape in Adobe Illustrator. Upon playing the stage, the surrounding edges of these terrain shapes become the collision vectors. Straight lines become single large vectors, and any bezier curves get split up into 8 or so smaller vectors. In the example of this loop, multiple small terrain edges, the vectors, are used to construct the solid surface. These are the blue lines. Sonic Studio works this way to allow you to create terrain with any vector polygons you wish to. It has incredible benefits, but a few extra challenges. Something to note is that Sonic Studio is a fan game created with GameMaker. GameMaker has no automatic built in vector/polygon collision system (it has a 2D physics engine, but that's not helpful for us at all). What little built in collision functions it does have is no use to us, because the classic Sonic games don't use complex sprite based collision. Everything has to be built from scratch using pure math, and that includes solving the issues that will be explained ahead. Let's go through the process for vector terrain edges:
To find it using the most direct approach, we would have to loop through all of them, checking the position, size, and rotation of all of them until we find a match. Each frame. That... is slow. Each stage could have thousands of these terrain edges. At the very start of Sonic Studio's development, me being new to this stuff, that's exactly what it did. But obviously if you try to make a stage of any reasonable size, this breaks fast. It's looking bleak. But not for long. So what's the solution? Solution Let's look back to that grid that the original games use. Hmmm. Seems simple. Seems nice. Let's copy it. Let's steal it.😈 Wait. Sonic Studio uses a grid too? Yes. Does it use collision tiles? No. When the stage is edited or loaded, all of those terrain edges are of course, generated. The terrain shapes are "built", and their collision edges are calculated along with the angles. As they are created they are all added to a big list. Here's where the copycat magic happens. We will cycle through this large list of terrain edgers, once. The first frame of gameplay. As it does this, for each one it can check the terrain edge's size and position and compare it to an imaginary grid. This imaginary grid will be our equivalent of the original game's tile grid (though in practice, the grid used in Sonic Studio is a little bigger than the original). We will call this grid the "edge grid". The imaginary edge grid cell that the vector overlaps will become a real edge grid cell, and that cell is given a list which contains references to that and any other terrain edges overlapping it. If a terrain edge overlaps 2 or more these edge grid cells, that same edge will be referenced in each edge grid cell. With that done, let's go through our new process:
Tadaa I have greatly simplified things here in my explanations, but I think the core idea comes across. This kind of optimisation is a must when it comes to collision, drawing shapes, processing objects, and much much more. Bye bye.
6 Comments
GrimmTombobulus
26/7/2023 05:37:10 pm
Very interesting. I'm working on a game with Sonic-esque movement myself so I'm unfortunately familiar with how much of a pain in the ass this can be!
Reply
Anonymous
28/8/2023 05:23:21 am
I was watching your video on terrain editing the other day (https://youtu.be/D4QgsmOHSEE?si=xN99pAe-VNd4IXXe) and got to the part where an elipse was chopped out of a larger polygon shape (at around 1:25). When this took place, I noticed that one of the grid units contained a piece of terrain with two slopes instead of just one.
Reply
Lapper
8/10/2023 10:15:18 pm
Within the grid system explained in this post, a tile can contain any number of terrain edges.
Reply
Jaden Garvey
29/8/2023 06:49:19 pm
Will it be possible to create your own sprites, backgrounds, levels, and bosses? Essentially turning it into a Sonic game creator, similar to Mario Maker 2 and Super Mario Bros. X?
Reply
Your comment will be posted after it is approved.
Leave a Reply. |
AuthorHi, I'm Lewis. I'm a 2D game artist, animator, illustrator, video editor, and game developer.
@LapperDev Archives
July 2023
Categories
All
This website uses marketing and tracking technologies. Opting out of this will opt you out of all cookies, except for those needed to run the website. Note that some products may not work as well without tracking cookies. Opt Out of Cookies |