Closed a-type closed 3 years ago
Hey, thanks for this, and pardon the very late reply. What you have looks useful to the use-cases this library seems to explore most often, so I'm for it. If it's ready, perhaps Paul should take a look at it given that he may feel that, as you say - it may be out of scope.
no, please, go ahead. if the conflicts are solved we should merge
Alright, I'll see if I can get back in context to do that :)
there are no breaking changes in this, is this correct? just the extended cannon functionality?
In theory! Are there tests I can run against it to be sure? It's been so long since I opened this PR, but I did my best to merge with recent changes.
The goal was to add some additional contact info to the collide event, and add two new events (collideStart and collideEnd) which can help track lifecycles of collisions.
only the examples,
yarn build cd examples yarn start
if everything works lets merge, and if something comes up we can figure afterwards. :-)
Yup, they all seem to work as intended!
awesome, thanks a lot! :-)
ps. you dont happen to have some kind of demo that we could use to help people understand the functionality they can now use?
Afraid not... to be honest I built this anticipating using r3f for more advanced game dev, but then I found https://rapier.rs and it's become my go-to JS physics engine instead.
Hello there! I've been looking into building games with React, and I love the fact that this library runs the physics engine in a worker. However, I found that even some basic game ideas require a more fleshed-out understanding of contact events than is currently provided, both in documentation and provided values.
This is an initial attempt at improving the data provided from the collide event so it can be used more easily. The main questions I wanted to answer:
To wit I added two new callbacks to body hooks:
onCollideStart
: called with{ body }
, the colliding bodyonCollideEnd
: also called with{ body }
, the colliding bodyThis is pretty much all the info Cannon provides with its corresponding start/end events, but it's enough to work with. At least with the identity of the other body, you can look up the collision and flag it as "beginning" or "ended."
Here's how I'm currently using my fork with local testing (unoptimized, rough sketch):
This is still quite a bit of code to add on top of the library, though, so maybe there would be room to expand this library's usage to manage these flags for you? That is, if you find this addition worthwhile at all. I know this library seems a bit more casual in terms of usage and maybe this level of complexity isn't something you want to introduce.