Rotation of imported model with physics


I’ve been using jMonkeyEngine for a while now, but I’m having trouble loading a model with physics into my game. I’ve been following the TestWalkingChar code, and using it on my own model. I can easily scale the model using model.setLocalScale() method however I am unable to rotate the model. It rotates correctly when I omit model.addControl(character), but of course I want to add physics.

Any suggestions of why this is happening?

Thanks in advance

The location of the spatial is defined by the RigidBody, move that to move the spatial or if its a non-world-object set the RigidBody to kinematic mode to have it move along with the spatial. This will make the RigidBody be unaffected by the physics but it will effect the physics objects around it based on its location and amount of movement that is applied. Note that a kinematic RigidBody needs to have a mass!

Thanks for the quick response!

Where does the RigidBody come into play? I am using a CharacterControl as the model is going to be a walking character. Or should I create a new RigidBody and make it the control of the spatial?

Well then use CharacterControl.setPhysicsLocation()

Sorry, I don’t think I explained myself clearly…

Moving the CharacterControl is no problem. However, my imported model doesn’t rotate at all when it is loaded. My code to load my character is below The rotation is needed because the shape is lying on its side and I need to correct it:


CapsuleCollisionShape cc = new CapsuleCollisionShape(1.5, 6f, 1);

CharacterControl character = new CharacterControl(cc, 0.05f)

Spatial model = (Node)assetManager.loadModel(“Models/RobotModel/robot.mesh.xml”);







The rotate function doesn’t seem to make any difference. Am I way off track here? I was previously using PhysicsCharacterNodes which were working correctly, but I didn’t update for a while, so now I’m a bit lost.

Thanks in advance.

1 Like

You have to set the viewDirection for the CharacterControl which rotates the spatial directly attached to it or use a node for the CharacterControl and attach the spatial to that to rotate it without using the viewDirection.

1 Like

Fantastic! Thank you for your help!

One final question: Am I correct in assuming that the CharacterControl nodes will behave much the same way as the previous PhysicsCharacterNodes did? I read another thread where there might be some problems:

Yes, its the same basic bullet object but there were some code improvements taken from native bullet added to our jbullet version.

Aaaargh, I’m still having problems. The view direction only rotates around the centre of the capsule shape. I still cannot rotate the spatial and/or the capsule to have them fit together. Even if I try and rotate the spatial, it reverts back to this position.

The picture below shows the situation:

I’m really sorry, I’m sure there is a simple solution but I just can’t find it…

Use a node as I said. The controlled spatial will be moved into the center of the capsule and its Z direction will be rotated towards the viewDirection. So best use a model whose waist center is at 0,0,0.

1 Like

Ah, I got it! I was attaching the control to the Spatial instead of the Node. Once again, thanks for your help!

1 Like