Open fenomas opened 8 years ago
Looks like both .ri and .rj vectors go to the same point, which is wrong. The vectors need to go to the surface on the respective body. Wish I could give you the fix but I'm currently on the phone.
Internally, the solver use these two vectors to check how much the bodies are overlapping. If they go to the same point, the overlap would always be zero and no contacts would need to be solved...
The easiest way to solve this would be to use the .sphereBox method instead. It's already done, why not use it?
Thanks, setting the two contacts to their respective surfaces solved the problem!
As for why I didn't use .sphereBox, I tried to, and couldn't get it to work - but now that I try it again it seems to work fine. Though I guess my version should be faster, since it can assume each voxel box is static and fixed size and axis-aligned.
By the way, it looks like .sphereBox can create more than one contact for each sphere/box pair, for the box's face, edge and corner. My naive version just creates a single contact at whatever point on the box's surface is closest to the sphere's center. Are more contacts necessary for things to work correctly?
Great! Actually 1 contact is enough. The problem is the normal. You probably want a different normal vector depending on if it's on a side, edge or corner. It should always point straight out of the sides, right? and on the corner you probably want the normal to point from the corner to the center of the sphere. If this is not the case, you will get a weird contact behavior.
Yes, this is what I'm doing - I find the point on the box's surface closest to the sphere (which might be on a face or an edge or a corner), and then set the normal to be the vector from that point to the sphere's center. Is that the right idea? If so then I was just wondering .sphereBox handles things as three separate cases.
That's one way to solve it and I'm not sure what the result will be - I'm curious to see how it goes.
.sphereBox does 3 cases depending on if it's a vertex/side/corner collision. Maybe this is not needed. If you could verify this I'd be happy!
Sure, I'd like to look at this. Is there any particular test content I can check to compare the results to the current implementation?
Cool. I guess you could try the stacks demo (demos/stacks.html), to see if the sphere/box stuff behaves weirdly. Go through all the cases in the dat.gui list to the right. Also would be nice to see what happens with larger penetrations. Maybe the FPS demo (examples/threejs_fps.html) could test that. Shoot spheres at the boxes, particularly at the corners & edges.
Hi, thanks for your earlier help with this.
I now have a custom shape for voxel terrain that collides spheres, and which seems to work, within a first approximation. But it seems to be very slightly nonphysical in some cases - e.g. a sphere rolling slowly across a voxel boundary. I wonder if you could take a look at the way I'm creating the contacts and normals, and see if things look off?
What I'm specifically doing is creating a contact at the point on the voxel's surface which is closest to the sphere center. Not sure if this is what cannon expects, or if it should be on the sphere's surface, or in between, or if each shape should get a point on its own surface, etc.
Here is the demo with the implementation - important bit is lines 50 - 70. Thanks!