Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upPrevent object passing through walls / tunneling (implement CCD) #5
Comments
This comment has been minimized.
This comment has been minimized.
|
I just added a poor man's solution to the tunneling problem. It detects if a body is outside the world bounds and then reverses the velocity and translates the body back. I tried via an event. Here is the code. Please have a look. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for sharing, but does this work? I ask because So what you need to do instead is simply set the body position to be inside the world, the engine will handle the velocity change for you. Either way, as you say this is indeed a poor mans solution, as it's only a solution to going outside of the world bounds. BTW note the event name is not What we really need implementing is speculative contacts. I'll get round to it at some point hopefully! |
This comment has been minimized.
This comment has been minimized.
|
You are right. velocity change is not necessary. Just the translation does it. |
This comment has been minimized.
This comment has been minimized.
|
+1 |
This comment has been minimized.
This comment has been minimized.
|
Still experiencing this issue, I guess it's still unsolved? |
This comment has been minimized.
This comment has been minimized.
|
It's a pretty big feature to implement really, I've played around with some ideas for this but I've not yet got much working. It's a tricky one. I'm considering implementing a simple version for now (ray casting) that should prevent some of the more obvious tunneling cases. |
This comment has been minimized.
This comment has been minimized.
|
Ok I totally understand, thank you so much for all your hard work :) |
This comment has been minimized.
This comment has been minimized.
|
Note that increasing |
This comment has been minimized.
This comment has been minimized.
|
Still having this issue using latest master as of e698b6b. I have somewhat mitigated it by halving the engine.timing.timeScale value. Not sure of the repercussions of this, but works for my simple use case. |
This comment has been minimized.
This comment has been minimized.
|
+1 |
This comment has been minimized.
This comment has been minimized.
|
@liabru for https://cubeslam.com I ported a few SAT implementations to javascript but finally fell for this brilliant SAT implementation and converted it to be a part of this library. It's very similar to your implementation but will also project ahead based on the polygons relative velocity to see if it will intersect and then returns a minimum translation vector which may be applied to keep two polygons from colliding if desired. I found it to be quite stable and fast even in the pace of cube slam. Unfortunately google code just shut down so the implementation code for it is not viewable online anymore. But you can download it and have a look at the narrowphase implementation in |
This comment has been minimized.
This comment has been minimized.
|
@slaskis I remember playing with cubeslam, awesome project! Thanks for the info. I actually played with using SAT for continuous collisions but I couldn't get it working at the time, so I'll take a look at your implementation for some pointers. |
This comment has been minimized.
This comment has been minimized.
|
@liabru thanks! I hope it can help you get this sweet library even better |
This comment has been minimized.
This comment has been minimized.
|
+1 Seeing lots of tunneling with bodies passing through svg generated bodies. |
This comment has been minimized.
This comment has been minimized.
|
Is there any workaround for this issue? The proposal from @abataille doesn't work for me. |
This comment has been minimized.
This comment has been minimized.
|
Not yet, I have a work in progress implementation. Depending on your needs, you could try doing some ray casts between updates (e.g. between centroids of bodies moving over a certain speed), if there's an intersection then move the body back. This won't be perfect but might help for some cases. |
This comment has been minimized.
This comment has been minimized.
|
@liabru would you mind sharing your in progress implementation as a PR or branch? I'm curious what it looks like and maybe we can help out? |
This comment has been minimized.
This comment has been minimized.
|
Will this also allow collision with simple lines? To be more specific imagine a force field, which limits you to not pass from both sides but has no thickness. |
This comment has been minimized.
This comment has been minimized.
|
@slaskis it is in a very unstable state, I was trying a different approach than using SAT. But it looks like it's not going to be viable, so I'm going to try implement it again in the same way you did. Looking at your code, the key part seems to be these lines right? |
This comment has been minimized.
This comment has been minimized.
|
@liabru Any update on this? It looks like you abandoned the CCD branch and maybe are implementing your new approach in a different branch? Perhaps I can help code it up. I'm trying to make a game for mobile and this is the most performant 2D physics JS library I've found so far. Just need to get this bit fixed. |
This comment has been minimized.
This comment has been minimized.
|
Does that solve the problem now? |
This comment has been minimized.
This comment has been minimized.
|
I have a similar problem with my project |
This comment has been minimized.
This comment has been minimized.
|
I have a partially working solution in a branch I've not yet pushed, but it still has some major issues. It's a tricky one. Maybe I should push it if other people are interested in helping? |
This comment has been minimized.
This comment has been minimized.
|
@liabru Sounds like that might be a good idea? Along with a brief description of your approach, and of the problems that still need solving might be helpful. |
This comment has been minimized.
This comment has been minimized.
|
In my use case, I managed to work around it by listening to collisionEnd event, check if the bodies were forced out of the viewport. If so, re-position that body to bring it back. (this is good enough for my use case because I only need to make sure no objects can get thrown out of the bounding rectangles. Hope this helps. |
This comment has been minimized.
This comment has been minimized.
|
Is this ever going to be continued? |
This comment has been minimized.
This comment has been minimized.
|
I was also wondering about that @qwertyquerty. Any progress on implementing CCD @liabru ? |
This comment has been minimized.
This comment has been minimized.
|
Also interested in seeing this feature. |
This comment has been minimized.
This comment has been minimized.
|
Any progress on implementing CCD |
This comment has been minimized.
This comment has been minimized.
|
object passing through walls,I met this problem, too. |
This comment has been minimized.
This comment has been minimized.
|
^^^ Me too |
This comment has been minimized.
This comment has been minimized.
|
Is there any way? |
This comment has been minimized.
This comment has been minimized.
|
EDIT 2: https://gist.github.com/fabienjuif/a7d9fc3e34e23f6000bcfc185dc0e341 EDIT: I fall into FPS issues, the engine run objects faster on 60FPS than on 30FPS. So don't try that at home :( I did this trick for now: // engine
// - run the engine several times, so we have the feeling the game is fast
// - also, this avoid collision detecting issue since CCD is not implemented yet in matter-js
let lastLoop = Date.now()
for (let i = 0; i < RERUN; ++i) {
Engine.update(engine, i === 0 ? delta : (Date.now() - lastLoop))
lastLoop = Date.now()
}And divide all my velocities by the |
This comment has been minimized.
This comment has been minimized.
|
+1 |
This comment has been minimized.
This comment has been minimized.
|
Question: could a bounty help push this issue forward? We'd be happy to contribute.
|
This comment has been minimized.
This comment has been minimized.
|
This really should be completed, considering it's such a big issue, and it's been open for so long. |
This comment has been minimized.
This comment has been minimized.
|
Is there any work in-progress to address tunneling issues? |
This comment has been minimized.
This comment has been minimized.
|
I'd also like to see the tunneling issues resolved. |
This comment has been minimized.
This comment has been minimized.
|
Any updates? |
Currently there is no continuous collision detection (CCD), so fast moving objects pass through other objects.
A description of the problem:
http://www.stencyl.com/help/view/continuous-collision-detection
Solution is to implement a CCD algorithm.
One I'm currently considering is speculative contacts, see here and here.
"we compute the closest distance d between the two objects; the idea is that we want to remove exactly the right amount of velocity from A such that it will be exactly in touching contact with B on the next frame"
I've already implemented the code that extends the AABB based on object velocity.
The next part is to find the closest distance between two objects and remove the required velocity.