Jump to content
  • Advertisement
Sign in to follow this  
DanMarshall

Gravity/ Platform overlapping problem...

This topic is 5456 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

I'm writing a 2D platformer in C and Allegro. Basically, when he's not colliding with tiles, his 'gravity' flag is flipped on. When this happens, his y coordinate is increased based on a counter (from 0 to 6). So when he falls off a ledge, his falling speed increases. The problem is when he lands, he can be overlapping a tile (by up to 6 pixels, depending on the length of the fall). At this point the gravity flag is obviously switched off. Obviously, I want him to land 'on' the tile. Is there an obvious and simple workaround that I'm overlooking here? I put in a bit so that when he's overlapping a tile, his y coord is reduced until he isn't. But this just makes a one-pixel bounce on top of the tiles when player->y is being reduced by one, increased by one etc. What am I missing here? Can anyone help?! Cheers, Dan

Share this post


Link to post
Share on other sites
Advertisement
Hey

What you will need to do is add some code to check, while he is falling, to see if he is close to the ground or not (or any object).

As you said it increases, so if he's on 6 and there are only 3 pixels to go untill he hits the ground, you must do a check.

e.g.

if( distanceToGround < fallAmount )
fallAmount = distanceToGround;



Then he should land square on the ground.


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!