[SOLVED] Gravity problem using BetterCharacterControl

When I am setting the gravity on BCC it doesn’t seem to have any effect

var betterCharacterControl = new BetterCharacterControl(1f, 6, 10);                         
betterCharacterControl.setJumpForce(new Vector3f(0, 10 , 0));                           
betterCharacterControl.setGravity(new Vector3f(0, -30, 0)); 

but when setting gravity using bulletAppState it works

this.app.getBulletAppState().getPhysicsSpace().setGravity(new Vector3f(0,-30,0));

I’m not sure how to use the gravity in BCC.


Set the gravity after you add it to the physicsspace.


Ah now it works thanks alot :slight_smile:
I think this tutorial https://wiki.jmonkeyengine.org/jme3/advanced/walking_character.htm
needs an update.


Is this something new? Shouldn’t gravity be set before adding to the physics space?
Works fine for me.

        playerControl = new BetterCharacterControl(1.5f, 6f, 1f); // construct character. (If your character bounces, try increasing height and weight.) 
        playerNode.addControl(playerControl); // attach to wrapper 
        // set basic physical properties: 
        playerControl.setJumpForce(new Vector3f(0,5f,0));
        playerControl.setGravity(new Vector3f(0,1f,0));
        playerControl.warp(new Vector3f(0,10,10)); // warp character into landscape at particular location 
        // add to physics state 
        rootNode.attachChild(playerNode); // add wrapper to root
1 Like

When you add it to the physicsspace it adopts the physicsspace gravity so it will be overwritten if you set it before. This basically means all physics objects have the same gravity as the physics space by default. So if you want it to be different you have to set it after.

I’m pretty sure it’s always been like that, but I could be wrong.


Yep, its only mentioned for RigidBodyControl.

I will fix these pages since each implies you are setting them rather than letting the physics space do the work.


Everything’s fixed and improved documentation. Thanks for the report.