I’m toying with a VehicleControl vehicle, I have a bit of difficulty trying to keep it above ground. When going too fast it crashes through the terrain and falls into the void. I need ideas on what to look for to avoid this.
I check the linear velocity vector and when it gets to be around length 25(-ish) I smack through the terrain. It also seems to be related to angle, i.e. if the velocity vector is more perpendicular to the ground I fall through easier (like falling from a height or running fast into a slope).
The terrain is the usual TerrainQuad.
terrain = new TerrainQuad(…)
CollisionShape terrainShape = CollisionShapeFactory.createMeshShape((Node) terrain);
RigidBodyControl terrainCollisionControl = new RigidBodyControl(terrainShape, 0f);
I create the control something like this:
CollisionShape vehicleCollisionShape = CollisionShapeFactory.createMeshShape(vehicleModelGeometry);
VehicleControl physicsControl = new VehicleControl(vehicleCollisionShape, 80f) ;
I’ve tried 4-6 wheels in different layouts but that does not seem to matter.
The collision shape looks like a snug fitting convex mesh when I use bulletAppState.getPhysicsSpace().enableDebug(assetManager);
But is that even used for Ray casting vehicles? It seems like if the wheels fall through the terrain the chassis also does so or perhaps I’m just imagining things.
The mesh has extents in the region of 10.50.25. Is that too small for Bullet?
The mass is 80f - a bit light for a car but it should still work?
Since it looks like it is speed related I turned on CCD
But I can see no change whatever values I try. I’ve tried values from 0.1f to 30f on Threshold and 0.1f to 20f on sphere radius. Both jBullet and native bullet behaves the same.
Obviously I’m doing something wierd but I’m stuck, anyone have a suggestion on what to try next?
Try raising the suspension maxForce.
Also if you use the native bullet you can set ccd to half radius of your car, if the object moves further than this amount, a sweep(ray with geometry) test is performed first, wich makes tunneling impossible.
I tried suspension max force and also setting ccd-radius to half the vehicle but I must have something really wierd going on in my code. I suspect that my experimenting with design/refactoring has tripped up some initialization or something.
I’ll have to write a test case to compare my code against but now I know it shouldn’t tunnel if I get CCD to work. Thanks for the tips!
I wrote a simple test case. It has one RigidBodyControl cube and two vehicles. I drop them on the terrain. It seems that a vehicle with wheels will tunnel through terrain a lot easier than a simple rigidbody (or even a vehicle without wheels).
I haven’t calculated the actual height they fall or the speed but the RigidBody cube can be dropped from something silly like y:850 before it tunnels. The ray cast vehicle only from 150 so there seems to be a difference. This is with jBullet and no CCD.
Don’t know what to make of this, is this expected behaviour and I should use some other control for my use case?
Only native physics use ccd as far as i know