Sign in to follow this  
GameGeazer

2D slopes

Recommended Posts

GameGeazer    1090
My friend and I are currently developing our first game, a 2D platformer. It is well along, but I cam across a problem. Currently in our game there are only Rectangle objects(such as Mario) that you can jump on where I detect a collision between the NPC/Player and rectangle; then set their Y equal to the height of their image plus the 'Y' of the rectangle they collided with. Using this technique I have been unable to create slopes or even triangle shaped ramps for the player to walk on. (curves such as in Sonic the hedgehog) How would I go about implementing platforms that have slopes into our game? also am i going about this the completely wrong way?

Share this post


Link to post
Share on other sites
sox    488
The _simple_ way would to be create some new sloped tile types... when the player is standing on a sloped tile, you'll set his Y position to something between the "top" and "bottom" of the tile, based on the X-position within the tile.

(For example, if you create a 45 degree tile (sloping up to the right), then the player's Y position would be half the total tile height when standing in the middle, or the entire tile height when he's standing on the right edge.)

If you really want lots of smooth gradients (or even loops, like sonic), you'll probably want to go to a collision system that uses line segments instead of tiles. It's a bit more complex to implement, but it gives you more freedom in your level design.

(upon re-reading your post, i think maybe you were talking about object vs object collision, instead of tile collision... in which case you probably just need to start by taking your rectangle vs. rectangle code and generalizing it to full line segment checks. )

Share this post


Link to post
Share on other sites
Valmond    112
You can make the player a circle too.

Quite easy to collide a circle against a rectangle (and dead simple circle vs circle).

I did some platformers a long time ago and I used (IIRC) just a line (top-bottom).

You don't (probably, anyhow if it's a classic platformer) need pixel perfect collisions so this would work quite well.

HTH

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this