Slopes in Side-Scrollers

Member
Posts: 269
Joined: 2005.04
Post: #1
Has anybody ever seen a tutorial on how to do sloping surfaces in 2D side-scrollers? Or better yet, does anyone have the source-code to a Mac game that had sloping surfaces?

I'm mostly having a hard time figuring out how to do the collision detection. Since my game is tile-based the easiest way to handle collision detection is to check the sprite against the tile. If the tile is non-passable, don't let the sprite enter the tile. However, sprites need to be able to enter part of a sloped tile. And the character needs to be able to over-shoot the tile by a bit other wise the character will look like it's floating in mid-air. It just really makes my head hurt thinking about the whole thing.

If you have no idea what I'm talking about when I say sloped-surfaces play Ferazel's Wand. It's got slopes up the wazoo.
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #2
I don't know the tools you are using, but did you look at Spriteworld?

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #3
Oops, I guess I should have mentioned what I was using. I'm using Project Builder and coding in Obj-C for Cocoa. I've used parts of SpriteWorld in the past and I don't think it has what I'm looking for. Actually, let me check on that real quick...

Nope, I couldn't find any info on sloped surfaces in either SpriteWorld or SAT. However, I did remember that Abuse has sloped surfaces and I have the source for that. Too bad the source is absolute hell to look at.
Quote this message in a reply
kainsin
Unregistered
 
Post: #4
Now it comes time to move from fully tile-based programming ( can move/can't move logic ) to pixel-based collision detection.

Simply put, you're going to want to try to make it so that when the character-object moves, instead of just saying "Hit a tile", say "Hit this much of a tile: [a rectangle of intersection between the player-object and the tile]".

Now take that rectangle of intersection and test all of the pixels of the player-object with the overlapping, non-transparent, pixels of the tile. If any of them overlap ( or are one pixel away from overlapping if you're doing pre-emtive collision detection ), then there was a collision and you can stop the player-object from moving.
Quote this message in a reply
swcrissman
Unregistered
 
Post: #5
If you still want to do simple tile collision detection, you could simply assign a series of height values to the terrain in each terrain tile, and then draw the character at the tile's y location plus that height offset. This would allow you to simply do tile collision detection, if I'm thinking correctly.

[example]
For instance, say you want your terrain to be able to slope and you want to divide each tile up into say, 20 possible positions. Each tile then would have 20 tile height values associated with it. When a player moved onto a tile, first you'd check and see if they are able to land on it, using the same formula you are using now. Okay, so they've landed, now how far are they across the x axis of the tile? 50%? Okay, so look at the 10th height value and see how high above the base of the tile you should draw the character. Say you find a 10. Great, when you draw the character, draw him at the level of the tile, +10 y pixels.

Now, assuming the slope is going up and to the right, as the character moves further across the tile, the y value offsets associated with the tile will increase a bit, so he'll be drawn a bit higher than before.
[/example]

I've never done this kind of stuff, so maybe I'm way off base, but it seems possible to do it this way. I don't know how complex your game is, but assuming its fairly simple, then this should work fine. If you're doing something complex, you probably just want to move on to doing per pixel checking. Basically, doing it this way doesnt add slopes to your game engine, it just makes your renderer draw the character as though he is moving along a slope. Obviously, the more accurate you want things to look, the more divisions you'll need in your array of heights for each tile.

If you're bouncing things off the ground, this will work pretty terribly, as everything will bounce as though the ground is flat, but be drawn as though its hitting a slope. Obviously not what you'd want to happen, but if you're just making a mario style game where you just need to see if the character is on the ground or not, this should be fine.

Spencer
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #6
You might also pick Chris D's brain since he made a side-scroller "Death from Above."

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Griggs
Unregistered
 
Post: #7
swcrissman, I have used that very technique sucessfully. Just remember to check the vertical lookup table (basically just a simple array) when calculating the collision before the player has already entered it when falling. Otherwise the last update could bring the player only a couple pixels down, which after falling faster than that in the last frame looks awfully strange.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #8
Thanks everyone! The height lookup table is similar to idea that I had. Each tile whould have a slope (rise over run) that would be used to calculate the vertical acceleration of the sprite. The lookup table is probably a more complicated way to go, but may be faster as it should take less calculations.

I'll try everything and hopefully find the best way through sheer experimentation.
Quote this message in a reply
Unregistered
Unregistered
 
Post: #9
You know, I have to add a little bit of brevity... You could just make the player's sprite really, really, really big. ^_^

alternately, the super mario bros approach could be followed-- don't make anything that is less than a tile large. ^_^

-joie
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Side-Scrolling pchukwura 7 9,758 Dec 27, 2010 10:14 AM
Last Post: pchukwura
  Beginner, 2D side scroller Why37 2 5,848 Apr 26, 2002 10:40 PM
Last Post: Why37