🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to calculate penetration of two AABB's colliding with each other?

Started by
2 comments, last by GoldSpark 3 years ago

Hello I am a beginner in game programming and I've started making 2D platformer game. When my character jumps and gets on top of some AABB platform he stays there but he is constantly vibrating or shaking. I am thinking that it is because I am not resolving the penetration depth? When he is on top of some AABB all I do is change his Y position to that AABB's position.y + size.y so the character stays on top and his Y velocity to 0.

If someone can guide me to right direction on how to make a character walk on top of AABB without shaking it would be awesome!

Thank you in advance.

Ayy lmao

Advertisement

GoldSpark said:
When he is on top of some AABB all I do is change his Y position to that AABB's position.y + size.y so the character stays on top and his Y velocity to 0.

Does not sound wrong, although you may want to use a min instead setting, so the character can still move away from the platform, and only penetration is resolved but not separation. But that's unlikely the cause of your issue.

Eventually that's the reason: After the collision is resolved, gravity will pull the character down again, causing penetration again. If you render the character using that position, it will penetrate. And if your timestep isn't constant, penetration depth also isn't constant, causing jitter. See https://gafferongames.com/post/fix_your_timestep/

Otherwise i propose to log things like collision happening or not, positons before and after resolve, penetration and timestep for each update​, which should help to find / understand the true reason.

@undefined Yes that makes sense the timestep! Thank you!

Ayy lmao

This topic is closed to new replies.

Advertisement