Advertisement

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

Started by June 04, 2021 01:37 AM
2 comments, last by GoldSpark 3 years, 5 months 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

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.

Advertisement

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

Ayy lmao

This topic is closed to new replies.

Advertisement