# FPS Camera Bouncing On the Terrain

## Recommended Posts

I have implemented FPS Camera by using Capsule Shape in Bullet Physics.

That works, however I see the player sometimes bounce on the terrain which is unrealistic behavior.

How do I make the player never bounce on the terrain using Bullet Physics?

##### Share on other sites
IIRC you set the restitution to zero on the shape.

However, it's a nightmare trying to implement a character controller with a rigid body. If all you are dealing with is height mapped terrain, I would suggest a sime ray cast and height offset instead.

##### Share on other sites

@Aardvajk: I already have the restitution set to zero, the player is still bouncing on the terrain.

Here is the code that I'm using with the player shape (Capsule Shape):

body->setCollisionFlags(body->getCollisionFlags() | btRigidBody::CF_KINEMATIC_OBJECT | btCollisionObject::CF_CHARACTER_OBJECT);
body->setSleepingThresholds(0.0f, 0.0f);
body->setAngularFactor(btVector3(0.0f, 1.0f, 0.0f));
body->setDamping(0.0f, 0.0f);
body->setHitFraction(0.0f);
body->setFriction(2.0f);
body->setRestitution(0.0f);

##### Share on other sites

Sorry, I don't have anything further to offer here. I just reiterate that it is almost impossible to use a rigid body as a character controller on anything other than flat terrains. As soon as you have any kind of slope, it becomes increasingly the case that the physics simulation of a capsule is not the same as the behaviour you want from a controller.

I suggest you take a look at btKinematicCharacterController in the Bullet source. It is not perfect and, last time I tried it, it has a lot of issues but it gives you an idea of how character controllers are handled differently to rigid bodies in a physics engine.

You can also look at my journal (link in my signature) which has some discussions on the character controller stuff I am currently implementing in my own project (no physics engine). That might give you an idea of how complex and awkward this is to get right.

What sort of environment are you working in? Height-mapped terrain, arbitrary solid shapes? The choices you have depend mainly on the kind of environment you need to get your controller interacting with.

Edited by Aardvajk

##### Share on other sites

@Aardvajk: Do I really have to use btKinematicCharacterController in order to get realistic FPS camera?

Can't I use btCapsuleShape and get a very good results? I'm thinking about doing raycasting and see what the player is walking on, if it's a terrain then I can simply set the player position to be on the top of the terrain, if it's not a terrain then I will let the physics engine resolve the collision.

Do you think this is efficient?

Also, do you suggest any other physics engine that can handle this problem better?

Thanks,

##### Share on other sites

It depends what you mean by realistic. If your game is based around the concept of a physical object moving around an enviornment then, no, you don't. If you are looking for a character controller that behaves like the controller in most first person shooters then you won't get that behaviour from a physics object easily.

As I said in my first response, if you are only dealing with a height-mapped terrain then a perfectly good approach is to raycast down from the position and set the height to a fixed offset above the ground. However, as soon as you want to collide with walls or objects, this approach fails.

My own approach is to use a combination - I have a capsule shape that I collide against the world with, but I combine this with a ray cast to find the ground to set the height and to only apply gravity when not on the floor. This stops the character sliding down slopes due to the minimum separation vector pointing outwards in the direction of the slope normal.

I believe Havok and PhysX both have a far more mature and battle-tested character controller included in their engine. Its something Bullet would benefit from enormously and I'm vaguely thinking about trying to port mine across, although don't hold your breath here, no intention of tackling this in the forseeable future.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982138

• 9
• 24
• 9
• 9
• 13