So I have a fast moving rigid body (grenade) and it clips through another rigid body (map wall). Setting the accuracy to 1/500 basically resolves the issue but causes jerky movement when using a character control. Also reducing the linear speed and using a larger collision shape helps but then the grenade moves to slow for me.
Do you know any more ways to solve/reduce the problem?
I believe bullet has an internal update loop of 1/60th of a second - or 60fps. So if the movement interpollation between frames just goes through it - your issue will arise.
e.g. in frame 38 it’s at point A - and frame 39 it’s past the wall - point B - the physics system saw no collision.
You could maybe fire a ray with a limit of the velocity to determine whether or not it’s going to hit something in the next frame, or make your “wall” bigger. Either way it’s going to need some kind of work-around or deterministic probability.
Ok, so what can I do about it if I need the rigid body moving fast (as fast as you’d expect a thrown grenade to move)? Perhaps fiddle with the accuracy, CCD motion threshold and/or CCD swept sphere radius?
The wall is already thick compared to the grenade collision shape, so perhaps I shoud use the ray solution. If I got it right, the ray should be used to periodically check if it hits an obstacle?
Well it’s just an idea but yeah. You should know it’s velocity and direction - so you can use that with a ray - which will effectively be a step in front - or a future position. So if a collision was detected by the ray, you just set it’s position to the collision point and make it go boom. Or set it slightly behind so it will bounce and continue it’s trajectory.
Nothing is perfect unfortunately. I would use the same ray with an agle of projection. Up down left right. A bit like a field of view indicator. Or you could accept not completely accurate results…i mean that grnade will decline in height and ur ray will see it at some point anyway if its fired in the direction its headed and not just straight ahead. There will be minor clipping but id take that as good enough to be fair.
CCD is (or should be) exactly that solution, it does a ray check if the object moved a certain amount within one frame. I did however notice that in jbullet CCD doesn’t always seem to work correctly, it seems it does work correctly in native bullet though.
Since our jBullet is already a modification, the original jBullet isn’t updated for years and bullet native is actually better in many cases (and in performance!)
Actually there is no reason to use jBullet (apart from maybe iOS)
Note: written in another language != incompatible with jME/unusable by Java. Native code written in C is usable from Java. Previously to accomplish this you had to write some custom C/Java code to bind the native library, although modern Java libraries like JNR can ease the pain of using native libraries considerably without sacrificing much performance. C++ code can also be used from Java, although that requires significantly more care than linking to C code. (Other native languages like Go usually also have some way to interoperate with Java.) In general, avoid native code if you can. Sometimes it’s necessary, but it adds a lot of complication and can easily lead to JVM crashes that are difficult to diagnose.