Best approach on character controllers?

Slin
Posts: 3
Joined: Thu Jul 17, 2008 2:48 pm

Best approach on character controllers?

Post by Slin »

I am currently trying to realize character movement on iOS devices using bullet. I am using a collission mesh with about 20k vertices as btBvhTriangleMeshShape and have up 10 characters active at a time. I initially wanted to use the kinematic character controller which is part of the bullet source, but it seems as if jumping isn´t really implemented yet and the bigger problem is that it is slow. With slow, I mean something like 300ms per 7 update steps on iPad2. A big optimization was to early out if a character didn´t really move, but that also isn´t really a good solution as I somehow managed to make the onGround check dependent on itself. What I just want is something where I can put in some movement direction and speed including gravity/jumping, which then will move my characters accordingly. I would probably do the intersection test seperately for the xz movement and the y movement. What I would love to know is, if the kinematic approach is the right way to go or if a rigid body based character controller could actually be maybe less stable, but quite a bit faster in the end.
Some hints on what I should and shouldn´t do would also be great :).

I just don´t have any deeper experience with physics simulation than throwing and grapping boxes, yet.
Thanks.
tea
Posts: 6
Joined: Mon Jul 18, 2011 6:42 pm

Re: Best approach on character controllers?

Post by tea »

I decided to go dynamic instead of kinematic. Got decent results (no benchmark though).

I don't want to use the character controller now, because I'm migrating, have a lot of not-physics-related code involved in moving my characters and intend keeping that code.

I setup like this:

- use a ball to simulate the character's feet. Set the ball to collide with the ground/platforms
- Instead of trying to set the linear velocity directly, use applyCentralForce() to push the body at every game frame, get feedback from getLinearVelocity() and adjust the force I input until it matches the target velocity I set (check 'servomechanism' on wikipedia; I started from there).
- I assign the ball's origin (minus radius for height) to the actor's location.

The advantage of using a servo is that you don't need to worry about the maths and it works regardless of friction, wind or existing velocity.

I don't assign the ball's 3x3 matrix to the rendered geometry. I let the ball rotate though. I know we can force a body NOT to rotate but I think a rolling ball is a decent approximation for walking/running feet and I don't know what's supposed to happen when we inject supernatural constraints.

I'm planning to post a little tutorial including the servo code. Let me know if you need it.

I haven't migrated my jumping code yet, it depends a lot on how precise you want it to be - could be a lot of work or 'as simple as adding an impulse'.