   2D Tilebased Platformer - Jumping Problems
  Hi, I've been working on a 2D tilebased platformer for a while now. I'm having some trouble with the jump logic. When I want the player to jump, I only want them to be able to jump if they are standing on something, (no double jumping just yet). My first approach was to have a small bounding box below the player's feet, and test whether it was colliding with any solid tiles. I found a ton of nuances with this method, such as the player being able to hold down the jump button, or hit the jump button and then press and hold it again very quickly, and they would just hop right along. After screwing around with this method and tweaking it to get it to work, I had ended up with a bunch of boolean variables and awkward logic in this convoluted system that honestly I can't even really remember how it worked and I'm shocked that it actually worked at all. It was pretty bad. Surely there must be a simpler way. I also seem to remember this method giving me problems when I tried to implement triangular tiles. My memory is a little bad because I had finally decided to take a break from that portion of the project and work on some other parts.One more issue that I had thought of is what if the player is standing on some sort of moving platform? If for example there is a platform that moves back and forth in a horizontal motion, it would currently slide right out from under the player's feet. I'm trying to think of some way to sort of keep the player snapped to the platform but I'm having some trouble here too.Has anyone here already tackled such issues?   
  These kinds of things are actually harder than they seem, but not impossible.  For jump logic, you want to check if you're touching the ground, and possibly add in a boolean if you jumped last update to prevent double jumps.  You'll want good contact information from your collision handler.  Ideally only real collisions with the ground should flip the 'touching the ground' flag.  Checking a sensor below you can work, but it needs to be super-thin or you'll be 'touching the ground' long before your character actually lands on it.  Another check can be simply if your vertical velocity is 0, which won't be true if you jumped/landed last frame.Moving platforms are a little trickier.  If your physics engine is pretty good then you can crank up the friction and hope it does the right thing.  It sounds like you're using your own physics system.  In that case, one solution is for the platform to have a sensor above it, which checks against objects that it might be able to 'move'.  Then you have to set that object's 'reference' velocity to the platform's velocity.  This can be tricky, since you don't want to change the object's actual velocity, otherwise any damping equations or current motion will get messed up.  One way to get around this is to actually move the object independent of the normal physics engine.  Another way is to have a per object 'reference velocity' variable which you reset to 0 after every update, but which the platform can set to its speed when it senses a collision.  I imagine there are other clever tricks, but this is the kind of thing that depends heavily on your physics and collision systems.;  If you want classic "Jumper", "Mario", or suchlike jump physics, having a simple "may-jump" boolean set when the character sets down on a surface is enough; let the player jump as often and as fast as they want, it's a skill.If you want more Prince-of-Persia (as in 1989, not 2003 or 2008) jumping, you want to create a state machine for your character's motion physics. Make a table of animations versus current input, and at the last frame of a given animation check current input to determine what animation to run next. Each animation also runs checks against terrain each frame to make sure it is still possible; if moving laterally and you find a wall, switch immediately to the "bounce" or "rebound and fall" animations, and suchlike.Stand:  +left/right: step  +up: climb/jump up  +down: crouchCrouch:  +left/right: roll  +up: standLast "step" frame:  +none: stand  +left/right: walk  +jump: hop  +hit wall: bumpWalk:  +run: run  +left/right: walk  +jump: jump  +down: rollRoll: crouch;  I used a bounding box much as you describe but with of height of 1 when using a true rectangular tilemap with no real problems. I'd set a flag once JUMP was pressed that prevented further jump signals until it was cleared when the button was released.When I was working with a polygon map recently, I found the following worked okay - I was using SAT to detect and respond to collisions, so was obviously generating a minimum translation distance vector for each intersection.If any of the MTDs were pointing upward, within a certain range, I set a flag that allowed a jump that frame.So basically if any object was pushing the player upwards, I considered the player to be standing on a ground surface and able to jump. If the angle of the MTD was not steep enough, the flag wasn't set.Worked okay.   ;  I assume your working in just an x/y coordinate plane. If so wouldn't it be as easy as the following...current_y; //where you are now.previous_y; //where you were.current_y - previous_y = delta_y; //your change in the up/down direction.if(standing && (delta_y==0)){ jump();}basically check to see if your character is moving up or down at the time and standing.-PickleEdit: then again...if your going to have platforms, your going to have to check to see weather or not the character is standing on something...so i guess you could just set a boolean flag. :)   