Multipart vehicle with several collision shapes

Hi,



I’ve been trying to contruct a working tank. The model consists of a chassis which is the parent of the turret which in turn is the parent of the gun.



I would like the whole package to behave like what one would expect from a tank. So far I’ve got the chassis working reasonably well. It’s got a CompoundCollisionShape which includes the turret and the gun. To drive it around it is controlled by a VehicleControl.



Now I would like to have the turret rotate on top of the chassis. For this I have assigned separate collision shapes to the chassis, the turret und the gun. My first attempt was to attach the turret using a HingeJoint and provide it with a RigidBodyControl to use for rotation.However this resulted in the problem that I had to use collision shapes that left parts of the model out as the shapes must not touch each other. Even then I had problems with the turret jittering although I couldn’t see the shapes touching in debug mode.



So I have tried to use a kinematic control for the turret. This works in a way, but now I’ve got a strange effect with the chassis. A long as it moves everything seems to be okay, but when it sits still it looks as if something is pushing it down. It sinks down on its suspension until the wheels sink into the ground and its collision shape touches the ground. When the chassis starts moving again, it pops back up on its suspension.



I have some doubts if combining a VehicleControl with a kinematic control like that, so maybe I’m going about this the wrong way. What would be the recommended way to assemble a multipart vehicle like a tank?



Thank you for taking a look at my problem.

The chassis is bouncing off the turret, use collision groups to avoid that.

So, I’ve tried this:



[java] turretControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);

turretControl.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_NONE);

chassisControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);

chassisControl.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_NONE);

[/java]



As I understand it, the chassisControl should not collide with anything anymore. But the chassis still sinks down. In fact, right now the collision shapes of the turret and the chassis aren’t touching, so the chassis should not be bounding off the turret anyway. Also I’m not observing the jittering that happens when two collision shapes overlap. Would it help to return to dynamic physics entities for the turret and gun?

Ah, then its probably just your vehicle settings, the suspension can be hard to get right.

Indeed, it even happens when I remove the control for the turret.



I have tried to tune the suspension settings, but nothing seems to affect this. Maybe it’s because the tank has more than 4 wheels. I guess I will have to do some more experimenting with this.

Try increasing the maxForce.

That helped at least a long as the tank is parked on a flat surface. But it still happens when some of the wheels are up on an obstacle. It works ok when the tank just drives over it or all wheels are on the obstacle, but when it stops midways, it slowly sinks down until the wheels touch the collision shape of the chassis, then suddenly it pops back up and the process repeats. No amount of maxForce seems to have an influence on the effect.



Maybe some images can make it a bit clearer:

Right after driving onto the obstacle. Suspension is almost fully extended





A few seconds later:





And still a bit later:





And then suddenly it’s on its way up again:





Maybe I shouldn’t park tanks on obstacles… :wink:

I have encountered this issue myself … Kinda curious as to why it happens.

@Normen: any idea?

The maxForce of the suspension doesn’t suffice, raise it :roll:

The mass of the tank is 20000. Now I’ve set the maxForce to 1000000 and it still happens. Though it takes longer to pop back up and it flies higher when it does. :smiley:



Do you really think I should set it even higher than that? The suspension is so stiff now that it behaves as if the wheels were welded to the chassis.

with 20000 kilograms mass the force definitely has to be bigger than the default, yes. getting the suspension to work right can be tedious, if the vehicle bounces you did it wrong :stuck_out_tongue:

I think I found it. Although I don’t understand the reason yet. I wasn’t using VehicleControl directly but through a child class. It was supposed to bring it to a certain speed and keep it there through the accelerate and brake methods. When the target speed is 0 and the tank is standing still, it releases the brake. If the tank starts to move, which it seems to do of its own accord for some reason, it reapplies the brake. As this happens in the update loop, the brake is applied and released several times a second. Maybe that has something to do with it.

Extending classes to add methods is generally a bad idea as a programming pattern unless you really want a similar class that just behaves slightly different. Especially logic like that should not be in the same class as the vehicle itself. Use Controls that you attach to the spatials that communicate with each other.