CollisionShape not updating in assembly? [SOLVED]

I have loaded my ships model as a BLEND-file and converted it into a J3O-file. The model consists of all different parts (hull, superstructure, guns, etc).



[java]ship = (Node)myAssetManager.loadModel(“Models/Fletcher/Fletcher.j3o”);

ship.setMaterial(myAssetManager.loadMaterial(“Materials/Fletcher/Fletcher_DD.j3m”));[/java]



To get access to the guns, I do:

[java]for (int i=0; i<qtyGuns; i++)

{

FiveInchGunTurret = i == 0 ? (Node)ship.getChild(“Five-Inch_Gun_Turret”) : (Node)ship.getChild(“Five-Inch_Gun_Turret.00”+i);

FiveInchGunBarrel = i == 0 ? (Node)ship.getChild(“Five-Inch_Gun_Barrel”) : (Node)ship.getChild(“Five-Inch_Gun_Barrel.00”+i);

gunTurretControl = new GunTurretControl(this, i);

gunBarrelControl = new GunBarrelControl(this, i);

FiveInchGunTurret.addControl(gunTurretControl);

FiveInchGunBarrel.addControl(gunBarrelControl);

}[/java]



and in the end I make a RigidBodyControl for the entire ship:

[java]ship_phy = new RigidBodyControl(shipsMass);

ship.addControl(ship_phy);[/java]



This works fine, but after firing the cannons I noticed that every now and then the shell fired by the cannon will explode right after it has been fired. With ‘bulletAppState.getPhysicsSpace().enableDebug(assetManager)’ I can see that the collision shape for the guns are not rotating when the guns rotate. My theory is that this is caused by applying the RigidBodControl to the entire ship-assembly. The collisionshape of the rest of the ship is turning when the ship is turning (also the collisionshapes of the guns, but these keep pointing in the initial direction when the guns are going to rotate to track a target.



Before I am going to make changes to the code, I want to make sure I make the right changes… Do I need to make RigidBodyControls for each gun to have them rotate with the gun? Or is there another way to make the collision shape of the guns rotate when the guns rotate?

The RagDollControl actually could help you as well. It creates a PhysicsRigidBody with a hull shape per bone (vertices with a certain bone weight) basically… Else yes, just making separate geometry and putting a RigidBodyControl on each would do as well.

Okay, thank you. I will check it out!

@normen said:
The RagDollControl actually could help you as well. It creates a PhysicsRigidBody with a hull shape per bone (vertices with a certain bone weight) basically.. Else yes, just making separate geometry and putting a RigidBodyControl on each would do as well.


That might be useful if you want to have locational damage too (i.e. shooting the guns off another ship).
Else, how about having the turrets as kinematic RigidBodyControls that you attach (jme scene graph wise) to the ship. The ship should be moved by the physics and the turret should move along with it, if you then locally rotate it (also in the jme scenegraoh) it should rotate the collision shape along with it..?


That's it, normen! Adding as a kinematic RBC and rotating the node (locally) does indeed rotate the collision shape. Thanks!

Hmm… I have done some trials with this and ended up with using a HingeJoint. Unfortunately, this is not giving the result I was hoping for, merely because the joint is not rigid enough (the cannon is not firmly kept into its location: it keeps moving a little). I need the cannons to be attached to the hull, so they will move together with the hull (I apply the forces for bouyancy on the hull only). If I do not use a joint, the cannons will start falling down and collide with the hull.



To be honest, I am a little bit lost in all the possible ways of achieving what I want and I was hoping someone could point me in the right direction for this kind of issue. What I have is roughly the following:

Blender

  • model of ship with cannons on it (WW2 Destroyer); hull and cannons are seperate objects in Blender



    JMonkeyEngine
  • physics implemented
  • ocean with waves
  • the Destroyer moving with the waves (by applying forces); destroyer imported as BLEND-file
  • the cannons rotating when they track a target (by adding a custom control to the cannons)



    What would be the best practice to firmly attach the cannons to the hull (cannons local position has to be fixed), but enable them to rotate (and with rotation, the colission shape has to update as well)? And with best practise, I mean the entire process.



    When it comes to creating the model in Blender, I see several option:
  • create the model as 1 entire mesh with an armature, do some weightpainting and move the armature in JME to rotate the cannons
  • create the model with separate objects for each (dynamic) part (like I did in the start of this topic)
  • any other?



    I have been looking around a little but can’t really find a similar example. Mostly, it is about importing one mesh with animations (organic-like object), but not about importing an engineering-like object like a ship. Somehow I am getting the idea I am looking/thinking in the wrong way here :frowning:

Hm, yeah the joints can be hard to get working properly, I also think theres still some bugs in jbullet. However, did you try using the SixDofJoint? Its very flexible but also very complicated to set up, I have to empirically find out how it works each time as well. Else, how about having the turrets as kinematic RigidBodyControls that you attach (jme scene graph wise) to the ship. The ship should be moved by the physics and the turret should move along with it, if you then locally rotate it (also in the jme scenegraoh) it should rotate the collision shape along with it…?

1 Like