slembcke/Chipmunk2D

Are the forums dead?

avahe-kellenberger opened this issue · 4 comments

It seems that signing up on the forums does not work. I have some questions about chipmunk (running into multiple issues with basic collisions) and can't find a community to talk to about the engine.

If there's an alternate group using chipmunk where I can discuss these problems, please let me know.

Ask here.

I'm seeing my player (a dynamic body) sort of "sink" into a static body, then slowly being pushed out (when falling from some distance).

I've tried both in pixel coordinates, and in "meters" where 32 pixels = 1 unit.

I'm also observing my player somehow sliding between two rectangles that are touching, if I move about them a bit.

chipmunk.mp4

I'm verified that the collision shapes are correct. I believe I'm likely doing something "against the rules" to cause this to happen, but I'm not sure what that would be. I'm simply updating the velocity of the body manually with user input.

EDIT: Should I be using a Kinematic body for the player in a platformer instead of a Dynamic body? I'm not sure how I'd detect and resolve collisions in that case.

Hmm, I thought we finally fixed the issues with the forum a couple months ago. Though it's been dead for kinda a long time... :(

Anyway, your issue in both cases is related. Chipmunk does not do swept collisions, so it only discovers collisions after they happen. When your character is moving quickly it might move 1/4 of their height in a single frame, and that's the "sinking" that you are seeing. When the player rises back up, that's how it resolves overlapping objects over time.

As for falling through the crack: collisions are resolved by using the direction of least overlap, and collisions are resolved one at a time. If the character lands deep into the corner of a block, the shortest direction can be towards the side. Now it's stuck between two immovable blocks, and both collisions are resolved by pushing the character to the side. :-\

So that's why it happens, and here's some ways to fix it:

  1. ALWAYS use a fixed time step. It's predictable and means the character doesn't move further on some frames than others. If something happens that causes you to drop frames, the character won't move a long distance between frames.
  2. Use a small timestep. Chipmunk is quite fast, and it's not really an issue to run collision detection at a 120 hz or more. (Especially considering that high refresh rates are quickly coming more common)
  3. Limit the terminal velocity of the character. This further prevents how far the character can move in a single tick, and makes the game more playable too.

Here's an old forum post with more relevant info: https://chipmunk-physics.net/forum/viewtopic.php?f=1&t=2434&p=10703&hilit=yourstory#p10703

And here is how I fixed the "sinking" effect in the game mentioned in that thread: https://github.com/maximile/Your-Story/blob/master/Classes/Player/Character.m#L157

Another game dev I know using chipmunk informed me that changing some of the space settings helps.

Iterations to 16,
slop to 0.001,
and collisionBias to pow(0.5, 60.0)
seem to be working very well for my game
(where one unit is 32 pixels).