[HELP]BetterCharacterControl weird jump physics

Example Vid: BetterCharacterControlPhysics - YouTube

Hello, I am trying to use a bettercharactercontrol as the character in my game, but i’m having weird super bouncing issues. I set the TownScene’s friction to 0.01 because i was sticking to walls, but even with it higher, this issue still occurs. I’ve tried increasing the player’s mass and that didn’t help. I’ve tried making my player short and fat as well as tall and skinny. In the example video, I was jumping, but i don’t always to jump to get this effect. Is the bettercharactercontrol broken or am i just using it wrong. i also have a related issue where every little bump sends my character flying up a couple feet.

PUBLIC CONSTRUCTOR{
    playerSpatial = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    betterPlayer = (Node) playerSpatial;
    playerNode = new Node();
    playerNode.attachChild(betterPlayer);
    betterPlayer.move(0, 1f, 0);
    betterPlayer.setLocalScale(0.03f);
    playerControl = new BetterCharacterControl(2.5f, 6f, 100f);
    playerNode.addControl(playerControl);
    playerControl.setJumpForce(new Vector3f(0, 1000f, 0));
    playerControl.warp(new Vector3f(0, 10, 10));
    playerControl.setGravity(new Vector3f(0, -20f, 0));
    app.getBulletAppState().getPhysicsSpace().add(playerControl);
    app.getBulletAppState().getPhysicsSpace().addAll(playerNode);
    cameraNode = new Node();
    playerNode.attachChild(cameraNode);
    cameraNode.setLocalTranslation(0, 6.5f, -1);
    localRootNode.attachChild(playerNode);
  }

 private void setUpKeys() {
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, "Left");
    inputManager.addListener(this, "Right");
    inputManager.addListener(this, "Up");
    inputManager.addListener(this, "Down");
    inputManager.addListener(this, "Jump");
}

@Override
public void onAction(String binding, boolean isPressed, float tpf) {
    if (binding.equals("Left")) {
        left = isPressed;
    }
    if (binding.equals("Right")) {
        right = isPressed;
    }
    if (binding.equals("Up")) {
        up = isPressed;
    }
    if (binding.equals("Down")) {
        down = isPressed;
    }
    if (binding.equals("Jump")) {
        playerControl.jump();
    }
}

@Override
public void render(RenderManager rm) {

    playerControl.setViewDirection(cam.getDirection().negate());

    camDir.set(cam.getDirection()).multLocal(3000f);
    camLeft.set(cam.getLeft()).multLocal(3000f);
    walkDirection.set(0, 0, 0);
    if (left) {
        walkDirection.addLocal(camLeft);

    }
    if (right) {
        walkDirection.addLocal(camLeft.negate());
    }
    if (up) {
        walkDirection.addLocal(camDir);
    }
    if (down) {
        walkDirection.addLocal(camDir.negate());
    }
    walkDirection.y = 0;
    walkDirection = walkDirection.normalizeLocal().multLocal(30);

    playerControl.setWalkDirection(walkDirection);//better character control
    cam.setLocation(cameraNode.getWorldTranslation());

}
1 Like

I can’t say exactly what’s wrong but I will point out some things that are strange…

It looks like you are using feet here instead of meters. You will be happier with meters and kilograms since physics will behave a little differently at different scales.

Especially considering that your gravity is set to the usual metric gravity for games, ie: double real gravity of -10 m/sec/sec.

As I recall, BetterCharacterControl works with forces so when you are setting the walk direction it’s like having a jet pack pushing the character in that direction. So the friction has nothing to do with why it is sticking to walls… if it sticks to walls it’s because a jet pack is slamming it into the wall so hard that it can’t slide. Turn off the jetpack if the character is not on the ground.

…that may also prevent a little of the floatiness. A better friction may also help.

Some other things that are more odd than problems… but may still be issues:

You multiply these by 3000 only to normalize them later. The multLocal() is unnecessary as it just gets removed by the normalization.

It’s not a problem, just strange.

JMonkeyEngine has many physics libraries, with slight incompatibilities between them: jme3-jbullet, jme3-bullet-3.3.0-stable, jme3-bullet-3.2.4-stable, Minie 1.5, etcetera. Which one are you using?

With BetterCharacterControl, the jump height is determined by the character’s mass, its jump “force”, and gravity. If you want jumps to go less high, either increase the mass, reduce the jump force, or increase the gravity.

There are a couple gotchas, however:

  1. The default jump force depends on the mass specified in the constructor.
  2. Gravity gets overwritten each time the control is added to a PhysicsSpace.

I therefore recommend printing out the values of these 2 parameters (at jump time) to make sure they have the values you intend.

He’s not talking about jumping specifically. He just used that in his title.

He’s talking about the problem where jumps send you into the air because the forces at the bump are so extreme that you fly up. Part of the issue with jetpacks and roller skates, really.

Yeah, on that piece in the middle, if i just walk on it to the tip and walk off, it is like a ramp and sends my guy flying as if i’m driving a car, not walking. I’m using these libraries exclusively for physics as far as i know:

import com.jme3.bullet.control.;
import com.jme3.bullet.util.
;
import com.jme3.bullet.collision.;
import com.jme3.bullet.collision.shapes.
;
import com.jme3.bullet.objects.;
import com.jme3.bullet.
;

I also changed my bettercharactercontrol constructor to use meters:
playerControl = new BetterCharacterControl(0.3f, 1.9f, 200f);

The radius seems small, but that was the most form fitting to my character and increasing it has no effect on this issue. The only thing I can think of that might help solve this is set the gravity to something absurdly high while grounded and then set the gravity back to -20 when I have been in the air for a certain small amount of time. That way when I jump or fall, it works properly, but if i’m going over a bump or ramp or something it weighs me down to the ground. I’m not sure how well this would work and this doesn’t seem like an optimal solution because I’m relying on a magic number for how much time is acceptable to be in the air before gravity stops being insane.

update: adding the gravity timer fixes the bumps, but not the ramps and it also results in my character jumping up way too fast. I wish i had a template that showed how bettercharactercontrol was supposed to work (one that worked well) to achieve walking instead of this that feels like driving a car.

i belive you really need higher friction and play with other params so friction will not make issues.

im using BCC, with lower friction i had same issues like you have.

also dont try set it to 1. 0.9 if you want it really high.

The more problematic are slopes, i needed configure so little terrain slopes do not make issue.

TestBetterCharacter, which is found in “JME3 Tests”/jme3-examples illustrates how BetterCharacterControl was intended to be used.

Here is a link to the official source code for TestBetterCharacter: https://github.com/jMonkeyEngine/jmonkeyengine/blob/v3.3/jme3-examples/src/main/java/jme3test/bullet/TestBetterCharacter.java

So far, here is what it sounds like the situation is to me, restated (I haven’t seen the latest code you have so I can’t be sure):

“When my rollerskating jetpack character hits a bump he goes flying through the air like he’s on roller skates with a jetpack pushing him along…”

Step 1: take off the roller skates (increase friction)
Step 2: stop the jetpack when his feet leave the ground… or at least slow it WAY down.

Else model the character with a jetpack on his back and give him roller skates. Then things will look fine. :slight_smile:

@sgold
the monkey in TestBetterCharacter sticks to walls. would it be better to maybe give him 2 capsules, one for the feet and one for the rest of the body to have friction on the bottom but not be spiderman?

@pspeed

wouldn’t stopping the jetpack when he leaves the ground make me lose all air mobility?

Perhaps.

Is something preventing you from writing a custom PhysicsControl for your game?

You should still have the momentum that you started with.

…but yeah, if you want to be able to change directions in mid air like super mario and stuff then you will still need the jetpack. Probably won’t need friction, though.