Public Group

# 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.

## 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 on other sites
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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46