Jump to content
  • Advertisement
Sign in to follow this  
Aardvajk

Bullet and character controllers

This topic is 3759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using Bullet at the moment, and everything is going swimmingly. Except that I can't quite figure out how to solve the following problem with my character controller - how to prevent sliding on slopes that are below a given gradient. I'm using a capsule for the character controller shape and a normal (non-kinematic) rigid body with an angular factor of zero to stop rotation and zero friction and restitude to stop sticking to walls and so on. I'm moving the character body by setting its linear velocity each frame. It all works beautifully except when standing on slopes. Even on fairly gentle slopes, the character gradually slides downwards (even if I give the body some friction), and when stopping when moving upwards on a slope, the character sort of jumps a bit in the air. Am I going about this in the wrong way? Is there a better way to do a character controller in Bullet than by using a rigid body? If so, how do you handle collisions with other moving objects (which works perfectly using the current system)? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I would be inclined to use (i.e. implement) a kinematic controller. Then every interaction with the physical world you have to implement explicitly, which means it will behave exactly as you want (so long as you implement it correctly!). Some things you'll probably want are:

- Sticking to the floor when the slope is "reasonable" (i.e. don't go ballistic when getting to the top of a slope even though "physics" says you should)

- Sliding nicely past geometry

- Ray or swept-sphere cast to get the floor position

- Smoothing of vertical movement

- Ability to climb steps

- Movement inertia ("faked")

- Gravity when you're not standing on anything

- Pushing other objects (just use forces)

- Getting pushed by other objects (just treat all other objects as completely immovable - bearing in mind they may move due to your own push forces)

- Interaction with other characters (probably handled by a character controller manager)

It seems that with character controllers you have two choices:

1. Start with a kinematic system and add in the dynamics you want.

2. Start with a dynamic system and remove the dynamics you don't want.

I think the second approach (i.e. Bullet's) is harder since it's difficult to specify exactly what physics you don't want, and it can also be hard to remove these things from the engine for your character.

Incidentally, the PhysX character controller is kinematic, and it gets stepped separately from the physics simulation. It can be made to behave quite nicely, in my experience.

Edit: Since you asked about interaction with other objects with a kinematic controller - it's quite simple to make a system where the character controller has got a significant skin width. Whenever objects are detected within that skin width the system applies a force. If the objects are moveable then they'll get pushed out of the way so never actually touch the character controller (CC) itself. If they're too heavy or don't accelerate fast enough then the CC will touch them and treat them as part of the world geometry so slide/stop against them. One nice thing is that you can tweak the location on the object that you apply the force - e.g. applying it at the object centre to remove rotation effects (useful if the player wants to push blocks around).

Share this post


Link to post
Share on other sites
Thanks for the response.

I've come to the conclusion (both from your post and from othe research) that I need to get a much better understanding of the maths behind 3D physics, even if I am going to get any use out of a library like Bullet or PhysX.

I guess it is a bit like trying to use Direct3D without any understanding of matrices and vectors - just too limiting.

Appreciate your advice anyway. I'm off to bury myself in research for a few months.

Share this post


Link to post
Share on other sites
Character dynamics need a lot of tweaking as they are not really representative of how a person really moves.

There are things such as automatically stepping over small obstacles (stairs), moving down a stair also require some special controller (else it feels very 'floaty'). Slopes as you say, better control on the actual movement (sharp acceleration and deceleration), interacting with other characters, scenery and rigid bodies, jumping and crouching, context sensitive moves (like jumping over barriers, hanging on ledges)... It can be quite involved to get it right without breaking the physics.

It's best done using proper available contraints, that's what physics engine do best.

Share this post


Link to post
Share on other sites
Currently bullet offers a basic rigid body based character controller. However, this has a variety of flaws and is not idea. A kinematic character controller was promised for the 2.69 release but you will have to check on their forums to see if this was followed up on.
[edit] It turns out this was promised for release 2.7 and not 2.69, according to the forums.[/edit] either way, it means that you may wish to focus on another area of your game and wait for this 2.7 release rather than implement the functionality yourself. Perhaps you can use a stop gap measure.

For very simple purposes you could get away with a single ray cast. IN this situation, you just cast a ray from the character's feet to the ground and any object that is contacted is stepped onto.

The physics engine Newton GD has a good character controller, which works by using a cylinder cast to detect objects that should be stepped onto, and a sphere cast to detect objects the character should move. any surface that protrudes into the cylinder is analysed to determine if the character should step up and down.

Quote:
Original post by EasilyConfused
Thanks for the response.

I've come to the conclusion (both from your post and from othe research) that I need to get a much better understanding of the maths behind 3D physics, even if I am going to get any use out of a library like Bullet or PhysX.

I guess it is a bit like trying to use Direct3D without any understanding of matrices and vectors - just too limiting.

Appreciate your advice anyway. I'm off to bury myself in research for a few months.


It my opinion that with a high level library, you only need to undrstand the principles of casting, and the matrix maths you mentioned. All else you will pick up as you go along. This was my personal experience.

Share this post


Link to post
Share on other sites
Another approach you might consider is overriding the contact point handling. I can't speak for Bullet as I've not had time to mess about with it yet - but many physics engines have some callback the application can define to map collision detection results into constraints (contact points) used by the solver.

For collisions involving a character's collision volume, just check if the contact normal is below your sliding threshold, and then crank up the friciton (and down the slip or any other contact point parameters the engine supports). Voila - he will slide along walls, but stick like glue to the ground. And the nice thing about solving it at the constraint level is that the solver's constraint solver can factor this properly into the motion of other rigid bodies in the system. In some solvers (particularly ones that allow interpenetration and then try and correct it), this will make the behaviour a lot more stable and stop bodies collapsing under force.

But having said this - you may well find that sliding down slopes is just the start of the character behaviour you want to override (for example, climbing ladders/stairs, jumping, pushing stuff, etc) - in which case, you might be better looking into a controller based solution for the longer term.

Share this post


Link to post
Share on other sites
Quote:
Original post by MudCake
Another approach you might consider is overriding the contact point handling. I can't speak for Bullet as I've not had time to mess about with it yet - but many physics engines have some callback the application can define to map collision detection results into constraints (contact points) used by the solver.

For collisions involving a character's collision volume, just check if the contact normal is below your sliding threshold, and then crank up the friciton (and down the slip or any other contact point parameters the engine supports). Voila - he will slide along walls, but stick like glue to the ground. And the nice thing about solving it at the constraint level is that the solver's constraint solver can factor this properly into the motion of other rigid bodies in the system. In some solvers (particularly ones that allow interpenetration and then try and correct it), this will make the behaviour a lot more stable and stop bodies collapsing under force.

But having said this - you may well find that sliding down slopes is just the start of the character behaviour you want to override (for example, climbing ladders/stairs, jumping, pushing stuff, etc) - in which case, you might be better looking into a controller based solution for the longer term.


I think this is exactly what I mean - I have no idea what you are talking about [smile].

I know you've implemented your own physics in your mighty cow game, and I suspect that with the level of understanding that you clearly have, customising an existing physics library to do what you want is feasible.

This is my ultimate goal - not to roll out my own physics engine to use in games but just to develop enough of an understanding to be able to work with a tried and tested engine but have the flexibilty to do what I want.

I think learning the basics of the underlying maths is the best way to start to get to this point.

Thanks (to MudCake and speciesUnknown) for the comments. (And MudCake, update your journal. I'm getting withdrawal pains [smile]).

Share this post


Link to post
Share on other sites

Just to confirm, the upcoming Bullet 2.70 will provide a basic kinematic character controller, similar to PhysX, Havok and Quake character controller. One of the Bullet developers is working it right now.

It is fully controlled by the user, so not based on a rigid body. It will use the btCollisionWorld::convexSweepTest, so you can choose any convex shape, like capsule, cylinder, convex hull, box etc.

Hope this helps,
Erwin
http://bulletphysics.com

Share this post


Link to post
Share on other sites
Quote:
Original post by erwincoumans

Just to confirm, the upcoming Bullet 2.70 will provide a basic kinematic character controller, similar to PhysX, Havok and Quake character controller. One of the Bullet developers is working it right now.

It is fully controlled by the user, so not based on a rigid body. It will use the btCollisionWorld::convexSweepTest, so you can choose any convex shape, like capsule, cylinder, convex hull, box etc.

Hope this helps,
Erwin
http://bulletphysics.com


Hey,
I've been looking forward to this new character controller. Do you have a known release date or approximate time frame for the 2.7 release, that you are able to divulge?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!