Need advice - which kind of constraint?

Post Reply
Chaster
Posts: 19
Joined: Mon Oct 01, 2007 7:24 pm

Need advice - which kind of constraint?

Post by Chaster »

Hello Bullet Folks,

I'm working on a game using Bullet (and Ogre) and it's coming along fairly well, but the issue of character control is rearing it's ugly head. Currently, I have a system which works, but is not quite good enough. (before you ask, yes, I looked at the character control demo in the latest version of bullet, but it is not good enough for my needs).

Here is what I currently do:

I using a dynamic rigid body sphere to dictate the position of my character. To move the character, I apply an angular velocity to the sphere. The spinning of the sphere causes the character to go where I want it. This works decently. When the character is trying to go up a hill, it slows down, and if the hill is steep enough, the character starts sliding backwards. This is as desired. Also, with the spinning sphere, I can make the character go up stairs fairly smoothly too. So far, so good.

Now, the problems:

1) The sphere is huge because it encompasses the whole character. I could make it smaller and put it at the feet of the character, but then no collision occurs with the upper part of the character which is outside the sphere.

2) The sphere tends to "ride up" when it bumps into other character of the same size. This isn't surprising since the sphere is spinning and is trying to "roll" up over the obstacle.

To counter these problems, I want to replace the single large sphere with a combination of a capsule (or cylinder) above a smaller sphere. (A search of the forum came up with a discussion mentioning this: http://www.ogre3d.org/wiki/index.php/Og ... _Character) I want the capsule/cylinder to be constrained to the sphere, but only by position. I.e. I don't want the capsule to orbit the sphere when the sphere spins. I want the capsule to stay directly above the sphere and remain vertical. Furthermore, I need the capsule to impart linear collision response to the sphere (so for example, if the character tries to run into a doorway which is too low, the collision of the doorway top with the capsule stops the entire character.

So which constraint should I use? Originally, I thought I should use a hinge, but that doesn't seem to work. Should I use a 6dof? If so, how do I set it up? I'm totally new to constraints in Bullet... Any help would greatly be appreciated.

Cheers,

Chaster
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Need advice - which kind of constraint?

Post by Erwin Coumans »

I don't recommend using dynamic rigidbodies to simulate a character controller. Currently Bullet provides such controller, but we will provide a proper one, based on kinematic motion, fully controlled by the user. Non-dynamic character controllers are most commonly used in games.

If you insist on using a constraint, you can add a btHingeConstraint to the capsule, using the up-axis as hinge axis. Attached it to a fixed rigidbody, and make sure the hinge only affects the rotation, by calling:

Code: Select all

hingeConstraint->setAngularOnly(true);
Hope this helps,
Erwin
Chaster
Posts: 19
Joined: Mon Oct 01, 2007 7:24 pm

Re: Need advice - which kind of constraint?

Post by Chaster »

I see that the Bullet maintainers propose using a kinematic body for a single character, and I can see how that would be easier for a single character, but I wonder - how will the kinematic character react when bumping into other characters? In other words, if you have a lot of characters moving around and bumping into each other, how does one handle that situation with a kinematic controller?

In the meantime, I'll try the hingeconstraint with angular only.. If that doesn't work as well as I need, then I may try another idea I have... Thanks erwin.

Chaster
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Need advice - which kind of constraint?

Post by Erwin Coumans »

Chaster wrote: how will the kinematic character react when bumping into other characters? In other words, if you have a lot of characters moving around and bumping into each other, how does one handle that situation with a kinematic controller?
Characters/people who bump into eachother usually don't follow the rigid body rules.

To keep control over gameplay, typically the collision response is handled by game logic instead. Some use a finate state machine, others simply stop both characters or let them slide, add some push etc.

Hope this helps,
Erwin
Chaster
Posts: 19
Joined: Mon Oct 01, 2007 7:24 pm

Re: Need advice - which kind of constraint?

Post by Chaster »

Well, I do admit that my situation is fairly unique in that I have many characters running around an environment which is itself moving (people inside a large ship) and the characters are often jumping, being pushed around by the environment, etc. The modifications necessary to handle these complex situations using a kinematic body would end up basically duplicating the functionality of a dynamic body...

Anyway, after a lot of experimenting with different schemes, I've come up with a system which I am happy with. I settled on using a dynamic rigid body capsule with zero angularfactor and impulse vectors coupled with direct manipulation of the velocity vector in certain cases (mostly stopping) when the character is touching the ground. It seems to work quite well and the simulation handles both static and dynamic environmental collisions pretty robustly.

I would post code as an example, but it's tightly coupled to the rest of my engine and wouldn't be very helpful...

thanks for your advice though Erwin. Much appreciated!

Chaster
Post Reply