CapsuleCollisionShape makes my character bounce

I am testing some physics, and I am making a flatbox as my “terrain” and trying some collision shapes for my character.

For my floor I have:

[java]

Vector3f center = new Vector3f(0f, -0.5f, 0f);

Box floor = new Box(Vector3f.ZERO, 100f, 0.5f, 100f);

Geometry floorGeo = new Geometry(“Floor”, floor);

floorGeo.updateModelBound();

RigidBodyControl floorControl = new RigidBodyControl(0);

floorGeo.addControl(floorControl);

floorControl.setPhysicsLocation(center);

rootNode.attachChild(floorGeo);

physicalState.getPhysicsSpace().add(floorControl);

[/java]

For my player, I have:

[java]

CollisionShape playerShape = new CapsuleCollisionShape(0.6f, 1.6f, 1);

CharacterControl player = new CharacterControl(playerShape, 0.5f);

player.setJumpSpeed(8);

player.setFallSpeed(12);

player.setGravity(10);

player.setPhysicsLocation(new Vector3f(0, 10, 0));

physicalState.getPhysicsSpace().add(player);

[/java]

For this configuration (using capsule collision shape), my player bumps a lot on the terrain.

If I change the stepHeight from 0.5f to 0.05f it makes the bumps really small, and almost unnoticeable.

If I change my shape to a sphere, using:

[java]

CollisionShape playerShape = new SphereCollisionShape(1.6f);

[/java]

The player does not jump at all, and moves very smootlhy through the surface.



Of course, using a sphere is not the desired shape for my player and will cause all types of different collisions with the terrain. And I cannot keep the setHeight too low, I would like the players to be able to automatically climb a half-block.

Anything wrong I am doing here, any suggestions on what to test?



Thanks for the help.

Theres absultuely no ‘bumping’ for the CharacterControl, it just falls and gets stopped by collisions. If you mean that its ‘in the air’ too much when going down a slope, raise the gravity or simply only activate ‘falling’ animation when its longer in the air than say 100ms

Sorry, maybe I was not clear enough in my post. And reading it again, I can see I actually wrote the behavior I am experiencing with the wrong wording.



My ground is completely level and my capsule remains on the ground level for most of the time, but while walking around, it sometimes go into the ground below me. So the lowest point of the lower spherical cap remains inside the big box I am using for the floor. And I keep walking, as I keep walking it eventually moves up again, and at some places, I can just leave the capsule parked in one spot, and I can see the capsule rapidly oscillating up and down really fast, making it look like its bouncing in place.



I hope this clarifies better what I am experiencing. If not, just let me know and I can make a video of it at home, and post a complete java code that makes it possible to reproduce the error.



By the way, to see the capsule, I am doing:

[java]

player.createDebugShape(assetManager);

rootNode.attachChild(playerDebug);

[/java]

And on the simpleUpdate:

[java]

playerDebug.setLocalTranslation(player.getPhysicsLocation());

[/java]



I am trying to figure out what I am doing wrong, so any input and suggestions are more than welcome.



Thanks.

Make sure your walkDirection does not point into the ground. Given enough force and gravity your character will go through the ground at some point.

I was just going to post about that as well. Seems that my combination of fall speed, gravity and step height is the culprit of my problem.

Will make sure to check my walk direction as well, to be sure is isn’t into the ground somehow.



Thanks for the tips.

So, after all my “bouncing” issue is with the stepHeight parameter in the CharacterControl constructor.

After resetting gravity and falls peed to default values, and setting the stepHeight to 0.05f (the same as on the Physics Sample), I get very little “bouncing” effect (character punching through terrain and going back up). I guess its a matter of finding the sweet spot value for this, but it seems this is going to b a long job.

I tried with 0f and 0.1f but both of them seem to be too little or too much, so I will have to try many values in-between. I just hope I am on the right direction. If anyone has any tips on this, or any links that helps me deduct a good value for that one (trying looking through the code, but its too complicated for me at the moment) I would be greatly appreciated.



Thanks for all the help already.

Cheers.