Advertisement

The theory behind collision response and sliding

Started by November 27, 2021 09:18 PM
14 comments, last by Gnollrunner 2 years, 11 months ago

@joej wow, i actually quickly tried your psudo code and it actually worked first time. Gonna try for all faces now :D

If collide-and-slide of an ellipsoid against arbitrary sets of triangles ('triangle soup') meets your requirements then this paper I found was very helpful..

http://www.peroxide.dk/papers/collision/collision.pdf

Advertisement

@brebarth221

brebarth221 said:

If collide-and-slide of an ellipsoid against arbitrary sets of triangles ('triangle soup') meets your requirements then this paper I found was very helpful..

http://www.peroxide.dk/papers/collision/collision.pdf

Great! You found it! I read this years ago when I did my collision stuff, and then I somehow lost the file and couldn't find it again until now. I'll reiterate a couple of things since it's here.

First you can optionally skip the ellipse part and either use stacked spheres or modify the algorithm to use 2 end sphere and then a bunch of sort of virtual spheres in the middle to form a capsule.

Second for general terrain it failed pretty fast for me (like after moving a few meters). After going into the debugger I found out why. As I mentioned before you have to do something about simultaneous multi face collisions or else you get into a deadlock situation. One face pushes you into the other which pushes you back to the first and so you can't actually move anywhere. This is a VERY common situation for general terrain (but maybe not voxel terrain) like when you are moving up a small valley. You can technically get many collisions at the same time but it's rare to get more than two, unless you made something like an cone that you fell into.

In any case what I did was add a slightly bigger sphere around the collision sphere that was used to determine all objects that you were “touching” after a collision. If you found you couldn't move after a normal collision, you find all pair combinations and do cross products of the normals to get possible response vectors. Then you compare all those responses to the direction you were tying to go (use dot product for that) and simply take the closest one. Again, the vast majority of times there will only be two collisions at a time at most, but if you want to do the general case, this works. You also have to make sure that any possible response is not blocked by another of your “touching” collisions. If you get it working right, the movement is smooth as glass over any terrain.

@Gnollrunner That's actually really helpful. I have one collision body in my current test setting on which the ellipsoid gets stuck all the time. This body has many quite small triangles, which probably touch the ellipsoid at the same time. Now I have a good idea of what might be the problem.

Another person wrote somewhere on some forum (can't remember which) that they had a problem with moving collision triangles (like, an animated collision world). Basically the whole collide-and-slide algorithm from that paper didn't work out for him. And the ellipsoid kept falling through, for moving objects. Haven't looked into that problem myself yet (didn't need it yet). But seems likely that this algorithm wouldn't be able to handle that requirement.

brebarth221 said:

Another person wrote somewhere on some forum (can't remember which) that they had a problem with moving collision triangles (like, an animated collision world). Basically the whole collide-and-slide algorithm from that paper didn't work out for him. And the ellipsoid kept falling through, for moving objects. Haven't looked into that problem myself yet (didn't need it yet). But seems likely that this algorithm wouldn't be able to handle that requirement.

That's a bit more tricky to solve with the standard sphere sweeping method. One nice thing about sweeping spheres is that you never get into the geometry no matter how fast you are moving. I'm guessing that a problem like this is better solved by the use of a physics engine, but it's not something that I've really played with so I won't give any advice here.

Once you can move the terrain you can imagine cases that are impossible to solve without getting stuck in the terrain. For instance say a sphere is trapped inside a space that it's physically do big to get out of. Now let's say that space decreases in size to the point the sphere doesn't fit any more. So really the sphere itself would have to have to put some constraints on the terrain morphing for this to work without issues.

This topic is closed to new replies.

Advertisement