planck.js icon indicating copy to clipboard operation
planck.js copied to clipboard

Bug? Continuous collision detection does not work after bodies are created

Open QuickMick opened this issue 3 years ago • 4 comments

edit: the real situation was different, than what i am describing here. it is not a bug with planck, see mein next post.

Hi, i have two dynamic bodies. The first one is my player, it is initialized like this: world.createBody({bullet: true}); The second one is created without the bullet-property. When i apply a strong force to my player object, targeting the second body, the player just goes through it. But when i first touch the second body slightly with my player body, and then apply the strong velocity, everything works as expected and the second body is thrown away.

i have tried to initialize the second body with

world.createBody({
  allowSleep: false,
  awake: true,
});

but this has not changed anything.

After both bodies have touched once, it seems that the CCD works always, but not right after initialization.

Am i doing something wrong, or is this a bug?

QuickMick avatar Mar 03 '21 23:03 QuickMick

Thanks for reporting this, could you please share a testbed example to reproduce it?

shakiba avatar Mar 04 '21 06:03 shakiba

i will try to create one tonight is there a way to set the testbed to a fixed timestep of 30ms?

QuickMick avatar Mar 04 '21 09:03 QuickMick

ok, i have investigated it further more. the problem is different from that what i was describing in my first post and its not a bug with planck.

Basically, i have a "spawn" protection, which disables the collisions for other entities till the player-body leaves the spawn. (the spawn is just a tiny body with static:true,isSensor:true) Unfortunately, in my case, the "end-contact" just resolves, after the player has crossed the other entity, so nothing happened.

How would you do this with planck? https://piqnt.com/space/7iE4dcA98 (wait 2 sec after starting for the initial impulse)

in my real project, i have an update-loop, that checks for each player in spawn, and turns on the collision, once the player has no contacts (m_contactList==null), in order to prevent, that collision is turned on, when two bodies are inside of each other. But that is also just called completely after the timestep and therefore does not work.

QuickMick avatar Mar 04 '21 18:03 QuickMick

Ah yes, you need to call refilter() after changing contact filtering:

bf.setFilterMaskBits(filter | 1);
bf.refilter();

Also you may want to check if the contact event belongs to your spawn, see SensorTest.

shakiba avatar Mar 05 '21 02:03 shakiba

I fixed this, now it automatically calls refilter after setFilter... functions. Thanks for reporting!

shakiba avatar Aug 26 '23 18:08 shakiba