Bouncing when hitting small hills

I try to create a character which the user can move through a landscape. The problem is that whenever the character runs against a steep slope, it bounces high. Changing the Gravity didn’t change anything - the character flew as high as before. For the physical landscape I use a RigidBodyControl, for the physical character a BetterCharacterControl.
I set the walkDirection like that:

[java]
@Override
protected void controlUpdate(float tpf){
Vector3f walkDirection = new Vector3f(0, 0, 0);
if (listener.getForward()){
walkDirection.addLocal(getViewDirection());
}
if (listener.getBackward()){
walkDirection.addLocal(getViewDirection().negate());
}
if (listener.getLeftward()){
walkDirection.addLocal(getViewLeftDirection());
}
if (listener.getRightward()){
walkDirection.addLocal(getViewLeftDirection().negate());
}
if (listener.refreshJump()){
creature.jump();
}
walkDirection = walkDirection.setY(0).normalize().mult(8);
creature.setWalkDirection(walkDirection);
creature.setViewDirection(getViewDirection().negate());
this.cc.getCam().setLocation(spatial.getWorldTranslation().subtract(getViewDirection().mult(40)).addLocal(new Vector3f(0, 14, 0)));
}
[java]

The object creature delegates the setWalkDirection() and setViewDirection() without a change to the BetterCharacterControl

This bouncing is not what I want of course. Can somebody tell me how to make the character go upwards without bouncing?

First of all, make sure, that at least one of the PhysicsObjects has its restitution set to zero. If this is not the case you should expect some weird behaviour.

The BetterCharacterControl behaves like an ordinary RigidBody in many ways. Your problem is caused by the conservation of momentum. So it is not a bug, it`s a feature. :smile:

However, you could counteract this effect by implementing a linear damping factor in y-direction. You might need to write your own CharacterControl, that extends AbstractPhysicsControl. Have a look at the source code of BetterCharacterControl:
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/bullet-common/com/jme3/bullet/control/BetterCharacterControl.java?r=10398
You just need to add some getter and setter methods for the physicsDamping in y-direction. But consider, that you do not want this factor to be applied in certain situations, e.g. when the player is jumping.

2 Likes