Log In  


Cart #52813 | 2018-05-16 | Code ▽ | Embed ▽ | No License

Hey guys! I'm doing a quick test on making a 2D platformer by using color-dependant collision. The only problem I have is what's known as the 'jitter problem', where because of gravity I need to set the player's y value over the ground, but when this happens after the player is in the ground it causes a noticeable jitter. (Try holding jump when on ground to see the effect)

Could anyone help me with this? I don't mind changing gravity and acceleration as long as it is similar. Thanks in advance! :)



try updating your position first, check for collisions and adjust the position value last in that same frame


As an aside, your math for jumping isn't how a jump actually works, physically.

There isn't a different state for being stationary, going up, and going down. There's just one state, where you're continuously accelerating downwards and stopping if you hit something. To jump, you add a large instantaneous acceleration upwards and then run the sim as usual afterwards.

Something like this, each frame:

  • set the player acceleration to the downward gravity constant
  • if jump button pressed, add a significant amount of upward acceleration to the player acceleration
  • add player acceleration to player velocity
  • add player velocity to player position*
  • check for collision/penetration and backtrack if needed to stop penetrating

* Note that when you add the player velocity to the player position, it can be worth breaking it up into smaller steps (within the frame) to avoid situations where your downward velocity is sufficient to step past an obstacle without actually overlapping it. If all of your objects are roughly 8x8, you might, for instance, want to step no more than 4 pixels at a time, maybe even 2, just so when you find they penetrate, you can easily decide which way to bounce the moving one.


Okay,thanks everyone! I’ll try to rework the jumping as @Felice described.



[Please log in to post a comment]