Collision Detection Problem

Hi, so this is infuriating. I’ve got a simple tile collision with a circular sprite. Here’s my update and collision handling functions, almost the exact same as the Platformer tutorial:

3

The order of functions called per frame goes like this: update(), on_message() for collisions, then collision_tile() to deal with the actual collisions:

Capture

2

It’s working fine and the player is correctly grounded while standing on the tile, however every 32nd frame, the update() function gets called twice instead of just once, as you can see in the last screenshot. That 32nd frame I guess skips out on sending a contact_point_response message and therefore switches the player’s state to “not grounded” for a single frame, causing a flickering in debug mode and some other annoying issues. Any idea as to why this is happening? The collision response code is working perfectly, without floating point errors or anything. It’s just that 32nd frame…

Is the project small enough to share?

If the “on ground” check is the main issue, I suggest using a small “trigger” collision object at the base of the player to check this, instead of using contact_point response. It’s much more reliable, and you can easily tweak the size of the trigger to have a bit of forgiveness.

Yes, the project can be looked at here:
exampleproject.zip (43.4 KB)

It’s very small, with the target code in the “char_player.script” file.
I’d rather not use an alternative method for now. It would be nice to have the thing working how the example tutorials show it being done. No reason to try to find a workaround for something so simple.

I would be very surprised if we forget to send a message every 32nd frame. Could it be that there is some hitch happening for one reason or another and you get a big delta and a big separation that makes your player completely separate from the ground for a full frame?

No, I printed the deltas and collision reactions and they’re all according to 1 frame’s gravity influence, as they should be.

It’s been a while, but I’m pretty sure it has to do with the collider shapes I’m using. The Defold tutorials use box colliders and their proper collision response process. I’ve been using circular colliders against box colliders, which requires a different response. When I switch to exclusively box colliders, it works perfectly.

Not a problem anymore.

2 Likes