Jump to content
  • Advertisement
Sign in to follow this  
GameGeazer

2D slopes

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!