Public Group

# Help with Platforming game?

This topic is 2571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Alright, I'm going to come across as a total noob, but I just wanna say I'm really not. I can competently code in a variety of languages- C++, C#, Python, PHP, etc. -and understand a LOT of theory behind game design. However, for some reason, making the beginnings of a platforming game are kicking my ass. Now, I didn't search the forums here too thoroughly (although, a lot of the top results didn't seem to helpful) but I have searched the internet as a whole and cannot find ONE good example of how to create a very basic, barebones engine for an old school platformer game. I understand so much of the theory and concept, but when it comes to implementation... idk. It always bugs out on me, and I have to restart from scratch.

What I'm basically just trying to do is make a single screen, tile based platform engine that allows a player to navigate the stage just by walking and jumping. Usually where I get hung up is how to resolve a collision between the player and the tiles. I can usually handle walking into a wall, say, but when I have to start accounting for gravity and jumping, I often get a character that gets stuck in blocks, falls below the stage limit, will no longer be able to jump, etc.

I'm using XNA to make this game, which means C# is the language I'm writing this in, but I'm more concerned with learning the basic structure of this system rather than specific code.

EDIT: When I said "resolve collision" I didn't mean collision detection in general. I know how to check for a positive or negative AABB collision. My question is AFTER deciding that YES COLLISION HAS OCCURRED, I have no idea how to reconcile the player so they are not stuck inside a tile, and being able to automatically detect whether the character is falling onto the ground, hitting their head on a block, or running into a wall.

##### Share on other sites
This is kind of what coding is about isn't it? Turning problem solutions into code. Is there something particular you're stuck on? Try making a game instead of an engine. A platformer engine is a rather vague description of a program

##### Share on other sites

This is kind of what coding is about isn't it? Turning problem solutions into code. Is there something particular you're stuck on? Try making a game instead of an engine. A platformer engine is a rather vague description of a program

I'm just sort of surprised there's not one good tutorial for a basic platforming game out there. The specific problem I have is resolving a collision between the player and tile such that the player cannot get stuck inside a tile. That's basically it. I understand programming involves problem solving, I'm just sort of flustered after about three weeks of not even being able to make a basic, functioning character.

##### Share on other sites
Hah, don't worry, I'm the same way. I get stuck all the time.

Collision detection is a weird matter. I never really thought too hard about it. A common way to handle it is AABB collision detection (Axis-Aligned Bounding Box). Basically you surround your objects with bounding boxes and check if they overlap on any of the axes. It's hard for me to summarize the process as I haven't really read any articles. I remember just seeing a picture showing the technique and getting the light bulb.

##### Share on other sites

Hah, don't worry, I'm the same way. I get stuck all the time.

Collision detection is a weird matter. I never really thought too hard about it. A common way to handle it is AABB collision detection (Axis-Aligned Bounding Box). Basically you surround your objects with bounding boxes and check if they overlap on any of the axes. It's hard for me to summarize the process as I haven't really read any articles. I remember just seeing a picture showing the technique and getting the light bulb.

No no, I get collision detection, especially the whole AABB theory. What I want to know is basically how do you resolve it? How do you decide whether the character has fallen onto the top, hit one of the sides, or bumped his head on the bottom and then move him without him getting stuck or anything inside that tile (or another one)?

The one theory I heard (and liked quite a bit, until it broke) was one where you basically took the rectangle created by the two boxes colliding, found out whether the penetration was deeper height-wise or width-wise, and then move the character in the direction it was most shallow. The problem with that was the force of gravity usually made a deeper impact than walking did, which would cause the character to get stuck on the edge of blocks.

And that was the best system I found. Most everything else has been crap.

##### Share on other sites
Can't really help too much without seeing the code, but if it's just basic rectangle collision your doing are you making sure when you detect a collision that the players position is moved to the position before the collision so you aren't stuck with the game thinking your constantly colliding therefor the players stuck.

e.g if you were walking right and hit into a tile:

if player intersects rectangle2
playerPosition.X = rect2Position.x - playerTextureWidth

//do whatever happens for collision

##### Share on other sites

//do whatever happens for collision

Obviously I've worded my question horribly. This is basically the part I'm looking for.

##### Share on other sites
I don't know what happened to the site, but it seems I lack any kind of CSS or javascript that was here before.

I had a similar problem. I happened to resolve it by taking the change in x and y and apply them separately to the objects. So take say, the change in x for the elapsed time, apply it, check collision. If collided, move up the objects to a position just before collision (snug it up to the colliding object). Then take change in y, rinse and repeat. I don't know a more efficient way.

##### Share on other sites

I don't know what happened to the site, but it seems I lack any kind of CSS or javascript that was here before.

I had a similar problem. I happened to resolve it by taking the change in x and y and apply them separately to the objects. So take say, the change in x for the elapsed time, apply it, check collision. If collided, move up the objects to a position just before collision (snug it up to the colliding object). Then take change in y, rinse and repeat. I don't know a more efficient way.

This seems to have worked to some degree. Thanks~

##### Share on other sites
One way I have done this in the past (at least for the vertical axis) is to create a loop in which I check if my player is overlapping a platform and then move the character up one pixel until the check fails to detect a collision. This is probably the least efficient way but it has the advantage of resolving the collision no matter how far the player is penetrating the platform (which in my experience can vary quite a bit!). I assume you could do similar for left/right/top edge cases too.

Here is some of the GML script I use for my GameMaker game:

 { test_obj = argument0; temp_y = test_obj.y; col_id = check_platform_collision(test_obj,temp_y,1); if(col_id >= 0 && test_obj.vy > 0) { test_obj.vy = 0; while(check_platform_collision(test_obj,temp_y,-1)>=0) { temp_y = temp_y - 1; } test_obj.jump = 0; } return temp_y; } 

It's not the cleanist code in the world (it was made as an example for my middle school students, but more a demo rather than an open source project). You can follow similar logic for colliding with the top part of a platform:

 collide_top = false; while(!climb && collision_rectangle(x,y, x + sprite_width, y + 2, platform_base, false, true) > 0) { y += 1; vy = abs(vy); collide_top = true; } 

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999991
×