Sign in to follow this  

Keeping your feet on the ground

This topic is 3863 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 apologize for asking what seems like such a basic question; unfortunately, the search tool didn't aid me much. If you have any relevant links or threads, feel free to send me off with those. Edit: this would probably be helpful. I'm working on a 2D platformer game here. In short, I'm having problems with properly recognizing when an object is resting atop another object (e.g. something standing on terrain). I'm using convex bounding polygons and SAT to detect collisions, which gives me, on collision, the normal of the edge that was collided with, and the distance along that normal that must be moved to be no longer colliding. I can also get the distance along the sprite's velocity to push back, though that requires an additional call. I've come up with the following requirements that I can think of to get a reasonable interaction with terrain:
  • Fall onto the ground, but not through it.
  • Stand on the ground without jiggling all over the place.
  • Jump off of the ground, but not be able to jump while in midair
  • Walk on flat ground, on up slopes, and on down slopes, without losing contact with the ground, losing the ability to jump, or getting stuck transitioning between tiles
  • Walk off of cliffs and correctly start falling again
I mention tiles there because I'm planning to break the terrain into discrete chunks, largely so I can perform small-scale deformations (e.g. vaporizing a set of tiles to reveal a hidden passageway). It seems clear to me that I need to have a "grounded" flag to indicate when the sprite currently believes itself to be standing on the ground. My difficulty comes largely from the last requirement - if I don't unset the grounded flag every frame, then the player gains the ability to walk off of cliffs, Wile E. Coyote-style; if I do unset it, then I get jiggling problems, because on every frame, the player falls slightly into the terrain, and is pushed back out slightly, to a new and different location. I don't suppose anyone here has any suggestions? The only thing I've been able to come up with requires abusing the fact that I'm using tile-based terrain to look for where the terrain should be and unset the grounded flag if it's not there, but I don't like how hackish that sounds.

Share this post


Link to post
Share on other sites
Quote:
Original post by Derakon
if I do unset it, then I get jiggling problems, because on every frame, the player falls slightly into the terrain, and is pushed back out slightly, to a new and different location.


Jiggling? If it falls in slightly and is pushed out again every frame, I thought that would just result in it sliding down slopes. The obvious solution to that would be some friction. Then maybe you can play with the friction force a bit to make it walk around.

Share this post


Link to post
Share on other sites

This topic is 3863 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.

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