BetterCharacterControl sinks through the ground

Im setting up a scene where a player falls a short distance to the ground. However when i start the application. The box sinks half way into ground. I read http://hub.jmonkeyengine.org/forum/topic/character-is-sinking-into-the-floor/ so i made the floor and charactor unit boxes. but that had no effect. Im just trying to understand whats happening here?

[java]
public void simpleInitApp() {
/** Set up Physics */
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);

viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));

setUpKeys();
setUpLight();

// We load the scene from the zip file and adjust its size.
sceneModel = new Node("scene node");
sceneModel.attachChild(makeFloor());

// We set up collision detection for the scene by creating a
// compound collision shape and a static RigidBodyControl with mass zero.
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);
sceneModel.addControl(landscape);

player = new BetterCharacterControl(.5f, 1f, 1f);
player.setJumpForce(new Vector3f(0, 20, 0));
player.setGravity(new Vector3f(0, -10, 0));

characterNode = new Node("character node");
characterNode.setLocalTranslation(new Vector3f(0, 5, 0));

Geometry b = new Geometry("Player", new Box(1, 1, 1));
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
b.setMaterial(mat);
characterNode.attachChild(b);
characterNode.addControl(player);
rootNode.attachChild(characterNode);

flyCam.setEnabled(false);
ChaseCamera chaseCam = new ChaseCamera(cam, characterNode, inputManager);


// We attach the scene and the player to the rootnode and the physics space,
// to make them appear in the game world.
rootNode.attachChild(sceneModel);

bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(player);

}

/** A floor to show that the “shot” can go through several objects. */
protected Geometry makeFloor() {
Box box = new Box(1, 1f, 1);
Geometry floor = new Geometry(“the Floor”, box);
floor.setLocalTranslation(0, -4, 0);
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.Gray);
floor.setMaterial(mat1);
return floor;
}
[/java]

Interesting if i increase the radius of BetterCharacterControl the box bounces like a trampoline… which i also don’t understand. but still only bounces after it has sunk into the ground

ok so after reading
http://hub.jmonkeyengine.org/forum/topic/charactercontrol-to-bettercharactercontrol/
im guessing i should not use BetterCharacterControl?

From the documentation you have

The box has a center of 0,0,0 and extends in the out from the center by the given amount in each direction. So, for example, a box with extent of 0.5 would be the unit cube.

So, when you create your box like this:

[java]
new Box(1, 1, 1)
[/java]
(in the creation of the player’s geometry), you have a box with a dimension of 2 for each vertex. So, when you create a bettercharactercontrol with a height of 1 (it’s pretty small and fat guy btw : 1m height, 1m of diameter … and 1kg … ).

So, first i advice you to change the dimension of the box.
Second, i think you should create the bettercharactercontrol with 0.3;1.8;80 (30cm diameter (still fat but ok), 1.8m height, 80kg).

And enable the debug for the physics, so you’ll be able to see the collisions.
You can enable it like this :

[java]
bulletAppSate.setDebugEnabled(true);
[/java]

Did as you suggested

[java]
bulletAppState.setDebugEnabled(true);
player = new BetterCharacterControl(.3f, 1.8f, 80f);
Geometry b = new Geometry(“Player”, new Box(.5f, .5f, .5f));
[/java]
which made perfect sense

but the scene behaved exactly the same . I can’t see any additional output from enabling debug either

the debug doesn’t do any output, except in the view. You should see wires around your meshes, it’s the collision. Then, you’ll be able to see if the pysic part sink into the ground (and it would be a problem) or if it’s only the graphic part. For exemple, i know that you have a difference between the charactercontrol and the bettercharactercontrol : in one of them (i don’t remember exactly) the spatial (=the visual part) is attached to the base, for the other it’s attached to the middle or the top. I really don’t remember which one do what, and this evening i am really tired. I’ll look further into it tomorrow.

btw, if you have a client-server app and the physics only server-side, you’ll not be able to see the wire with the debug part - which make sense, as the client doens’t have physics (except if you have also physic client-side).

I’m having the same problem.

I solved the problem by attaching my character to a node and adjusting the character within the node. Here’s the code:

[java]Spatial playerSpatial = assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
player = (Node)playerSpatial;
Node playerNode = new Node(); // this is the wrapper node
playerNode.attachChild(player);
player.move(0,3.5f,0); // THIS IS WHERE WE ADJUST THE LOCATION RELATIVE TO THE NODE
player.setLocalScale(0.5f);

    //rootNode.attachChild(player);
    /* Load the animation controls, listen to animation events,
 * create an animation channel, and bring the model in its default position.  */
    control = player.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim("stand");
    playerControl = new BetterCharacterControl(1.5f, 6f, 1f);
    playerNode.addControl(playerControl);
    playerControl.setJumpForce(new Vector3f(0,5f,0));
    playerControl.setGravity(new Vector3f(0,1f,0));
    // Finally we put the player in its starting position and update its state – remember to use setPhysicsLocation() instead of setLocalTranslation() now, since you are dealing with a physical object.
    playerControl.warp(new Vector3f(0,10,10));
    // We need to register all solid objects to the PhysicsSpace!
    bulletAppState.getPhysicsSpace().add(playerControl);
    bulletAppState.getPhysicsSpace().addAll(playerNode);
    rootNode.attachChild(playerNode); // don't forget to add to root.[/java]

If you increase the mass and height of your BetterCharacterControl, your character will stop bouncing. I’m not sure why increasing the height affected this, but it did. For example:

Change:
[java]
BetterCharacterControl(.5f, 1f, 1f);[/java]

to something like:

[java] BetterCharacterControl(1.5f, 6f, 4f);[/java]

(The width may be fine at .5f, but you will need to experiment with it yourself.)

I’d expect something only 1 kg to be pretty bouncy.

If you imagine something that is a full 1 meter wide (0.5 radius) and 1 meter tall that only weighs 1 kg… that reminds me of a giant air-filled bouncy ball.

If this is supposed to be a person then you could try setting them to person-sized numbers. Maybe (0.2, 1.8, 80)

I’ve never used BetterCharacterControl but I usually expect a physics engine to behave a certain way in light of the parameters givens. It could be a bad assumption.

Edit: note oto may be a bit wider/taller maybe.

You just need to lower your root bone and i’m guessing the root bone on your model is above the feet. First make sure your skeleton’s feet just just touch the floor grid . Then tab into edit mode and add a new bone have zero rotation making sure its bottom tip has zero translation . Select the root bone then this bone in blender then hit ctrl +p to parent your previous root bone to the new root bone.
Anything below the rootbone in blender will fall thru the floor in jme