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());
}
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.
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:
The default jump force depends on the mass specified in the constructor.
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:
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.
@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?
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.