Issues implementing CastShape function for custom shape #1381
-
BackgroundI'm using Jolt to add rigid body dynamics to my blocky voxel game, and I'm implementing a custom shape to represent the world. Thanks to Jolt's excellent docs, this hasn't been too difficult. For objects with the discrete motion quality, this was surprisingly easy. I only had to register a CollideShape function. The strategy I used here was to loop over all the blocks spanned by the AABox of the other shape, make a translated box, then call When I decided to try The issue(s)Unfortunately, I encountered two issues that I think stem from my implementation of CastShape being broken. Starting with the simpler:
frogRender_hv0NjOggoP.mp4What I've tried + observations
I'm fairly certain the issues with my character are a byproduct of my CastShape function being broken, but I don't know how. Either way, regular rigid bodies tunneling through my shape seems like a fundamental issue that needs to be fixed before moving on. Are there any common gotchas when implementing a CastShape function? Maybe there's someone else who tried making a custom shape for voxels with Jolt? Surely I'm not the only one 😅. If not, this issue could serve as a resource for others in the future (I did search the issues and found none that seemed like my particular problem). Code |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I would suggest to create a debug probe like the Samples to test your Looking at the code, I think the problem is that you're not making the cast shape relative to the box: https://github.com/JuanDiegoMontoya/Frogfood/blob/45275d1874af6e84e74e446bcdc56c41594eb060/src/Voxels/Physics/TwoLevelGridShape.cpp#L117 This
Another suggestion that I have is to not new the
That saves 1 dynamic memory allocation per cast. Finally, you can improve the 'broad phase check' by not testing the bounding box of the shape + shape moved by cast direction, but by adding the size of the bounding box of the cast shape to your target box and casting a ray against the box. Example here: JoltPhysics/Jolt/Physics/Collision/Shape/CompoundShapeVisitors.h Lines 178 to 190 in e0e434f |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestions. I'll implement these then let you know how it went. |
Beta Was this translation helpful? Give feedback.
I would suggest to create a debug probe like the Samples to test your
CastShape
function.Looking at the code, I think the problem is that you're not making the cast shape relative to the box: https://github.com/JuanDiegoMontoya/Frogfood/blob/45275d1874af6e84e74e446bcdc56c41594eb060/src/Voxels/Physics/TwoLevelGridShape.cpp#L117
This
inCastShape
should be replaced by something like:sCastShapeVsShapeLocalSpace
takes a local space cast as the function name suggests, the center of mass transform that is being passed in is only used to transform the normals and contact points to world space.Another suggest…