2d platformers and various ways to make them

Discussion and feedback on Construct 2

Post » Sun Jul 31, 2016 11:38 pm

Hey all,

I just wanted to share a quick blurb on 2d platformers and their implementations. I think it is quite common to hear that the engines are hard to make. They really are not. At this point (as a programmer that is self taught) I have successfully created 4 different types. I started with XNA and C# and wrote my own collision algorithm for my first. I am going to outline the general ideas involved with each type and what I learned from the experience. Briefly, here they are... of course, the distinction between the types can be blury at times...

Raycast 2d platformer,
Physics based platformer,
Geometry based overlaps platformer,
Point based platformer.

RayCast Platformers

Platformers using raycasts are common these days. They are fairly straight forward to implement. They are nice because you don't neewd to worry about resolving collisions. Instead you make sure that objects that shouldn't overlap never overlap. You do this by shooting raycasts from the characters leading edge and look for upcoming collisions. You use the distance between the character and the upcoming collisions to determine how far you can move the character. You can use engines like box2d to provide raycast functionality or you can role your own engine. But why invent the wheel when you already have rockets. Dustforce is a notable game that uses this idea. Most game engines have raycasts built in (c2 is an exception, but it shouldn't be).

Physics based platformer

Most people think of games that actually involve physics and have a certain feeling such as limbo. But in reality, you can make a retro style game like megaman using physics without too many problems. You have to create a number of systems to detect where the character is (on ground, in air, etc). This is most easily achieved using raycasts, but overlapping geometry can also be used. Using constraints and applying forces such as friction yourself, and directly controlling velocity, you can pretty much make any retro style platformer. It doesn't take more work than rolling your own engine, it just requires an excellent working knowledge of how the physics engine actually works. Box2d is a fine choice. One of the top hits in google when searching for "platformer physics" is a popular blog that says you can't/shouldn't use physics to make a platformer. I can only conclude the author is either not accomplished at programming or lacks creative problem solving. An important note is that in construct 2 , there are many features missing from physics that makes it much harder to use to make a platformer without compromises (such as tripping on internal seams).

Geometry based overlaps platformer

Rather than preventing collisions, this style of platformer moves the character regardless of collisions, then attempts to resolve the collisions after the fact. The overlapping algorithms are fairly straightforward to implement if you have to roll your own, but figuring which direction to resolve the collisions is the tricky part. C2 has a great collision system that makes using this method feasible in c2.

Point based platformer.

Welcome to retro land! This is one of the simplest and easiest methods to implement and was the choice method for a decade. Mario and sonic used this method at one time. Essentially you make a character have points that represent its head, sides, and foot. If the points overlap solids then the point react in a specific way based on where it is. In mario 3, if his head overlaps a tile the game simply changes his upward velocity to 0. If a foot overlaps it pushes him up. You get the idea. The trick is all about where you put the points and this takes some time to figure out. You don't want the foot to be overlapping at the same time as a side on the same surface. In the case of mario 3, to handle slopes mario actually changes the position of his foot points to be more narrow. If you play a level that has slopes, mario's collision boundary is actually different than in levels without slopes.


All in all, regardless of the method used to make a platformer engine, adding slopes, ladders, oneways, moving platforms start to make it harder to make. Slopes in a raycast system or physics system are easier to add than in a point or overlap system.

The best place to start when trying to make a platformer is to actually google it and start learning. Simply adding the platformer behavior without understanding why it works makes it really hard to customize.

Cheers
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Mon Aug 01, 2016 10:28 am

Thank you for sharing this information, it does provide a useful insight into how platformers work at their core. The only think I'd argue about is this: Making a simple engine may not be that hard everyone says it it, but making a general purpose, well optimized engine is not something that could be done easily.
B
129
S
33
G
17
Posts: 1,552
Reputation: 20,515

Post » Mon Aug 01, 2016 2:49 pm

Wow, nice post. Yeah, I've been wondering what kind of 2D platformer engine the Sonic game used that he can run & rotate like a roller coaster in 360 degrees.
But I understand Scirra Team wants to do it slowly, 1 at a time to make the program as stable as possible.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
55
S
17
G
90
Posts: 1,112
Reputation: 59,151

Post » Mon Aug 01, 2016 5:17 pm

While the Platform behaviour offers decent functionality, it lacks a lot of more complex stuff (like selective solid collision) and is hard to walk around it.

For some time I wanted to build my own platform functionality using events, but didn't know where to start. I am interested in a mario/megaman/kirby type, simple platform with slopes. I would like to avoid Physics since are using more CPU. Which method should i choose ?

Also, I've found the following tutorials to inspire from:
http://www.gamasutra.com/blogs/YoannPig ... hp?print=1
http://www.gamedev.net/page/resources/_ ... mers-r2936
http://www.hobbygamedev.com/adv/2d-plat ... -detection
B
49
S
15
G
6
Posts: 531
Reputation: 7,189

Post » Mon Aug 01, 2016 5:51 pm

Thanks for your post, @Ruskul. I have also been frustrated by the limitations of the platform and physics behaviours - and I never understood why your simple modifications to the box2d plugin were not implemented. Thanks to your post here I have decided to try to create my own platform behaviour - to compare performance / to enable collision filtering etc (using the raycasting plugin). I've also started (slowly) learning C#.... just in case lol....
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,193

Post » Fri Aug 05, 2016 6:55 am

@ruskul Can you give me some pointers regardless my previous post ?
B
49
S
15
G
6
Posts: 531
Reputation: 7,189

Post » Tue Aug 09, 2016 9:28 pm

glerikud wrote:Thank you for sharing this information, it does provide a useful insight into how platformers work at their core. The only think I'd argue about is this: Making a simple engine may not be that hard everyone says it it, but making a general purpose, well optimized engine is not something that could be done easily.



Making a general purpose anything when it comes to programming is difficult and typically should be avoided, unless that is the intent of the project (like making construct, yay). Most of the time, if you make your own, you will remake it next time, because even if you tried to make it general and flexible you didn't think of your next use case.

The very fact that I make my own when construct 2 comes with a pretty good basic platformer is a testament to this. It just couldn't do what I needed it to do, so I had to make my own.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Tue Aug 09, 2016 9:31 pm

chadorireborn wrote:Wow, nice post. Yeah, I've been wondering what kind of 2D platformer engine the Sonic game used that he can run & rotate like a roller coaster in 360 degrees.
But I understand Scirra Team wants to do it slowly, 1 at a time to make the program as stable as possible.



Somebody, if I recall, created a sonic clone on game maker that was a gigantic project. You could dl the project at the time, but it was expert level game maker stuff. The loops are mostly achieved through trickery. Its not like it actually has a robust physics simulation controlling. I never played sonic much nor analyzed it but if I recall there is this magic threshhold where you either do the loop or bail. You couldn't stop half way through at upside down.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Tue Aug 09, 2016 9:37 pm

TGeorgeMihai wrote:@ruskul Can you give me some pointers regardless my previous post ?



Sorry to get back to you so slowly. I haven't been online much as of late.

If you want to make your own platform behavior in c2, I would recommend the point based system. Adding slopes can make things a bit harder, but totally still doable. I have a system moldering on my hardrive, but I used custom behaviors to make it rather than doing it all in events. This makes it faster if that is a problem but I also needed the flexibility of code due to a few "key" features.

If you would like, I would be happy sit down at some point and go over how to implement such a system, specifically in construct 2 through events, unless you like coding behaviors instead... either way. If you like the way mario 3 felt, or kirby, then Its a great system, but there are some funny bugs that can be exploited (lots of mario 3 tricks, for example)

I keep meaning to edit the original post to give more info on how to actually achieve it.- though I should probably do this in a tutorial series.
Last edited by ruskul on Tue Aug 09, 2016 9:40 pm, edited 1 time in total.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Tue Aug 09, 2016 9:39 pm

TGeorgeMihai wrote:While the Platform behaviour offers decent functionality, it lacks a lot of more complex stuff (like selective solid collision) and is hard to walk around it.

For some time I wanted to build my own platform functionality using events, but didn't know where to start. I am interested in a mario/megaman/kirby type, simple platform with slopes. I would like to avoid Physics since are using more CPU. Which method should i choose ?

Also, I've found the following tutorials to inspire from:
http://www.gamasutra.com/blogs/YoannPig ... hp?print=1
http://www.gamedev.net/page/resources/_ ... mers-r2936
http://www.hobbygamedev.com/adv/2d-plat ... -detection


-

I should also point out that there are some hacks to get around solid collision enabling/ disabling, which could allow for the use of the behavior that comes with c2. I didn't like that behavior for the reason you do, but I also didn't like how it handled slopes and corners.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests