Tips on character movement

ill
Posts: 7
Joined: Sat Jan 29, 2011 4:14 am

Tips on character movement

Post by ill »

I've looked at tutorials on doing character movement with bullet and have seen many different techniques. Basically this always seems like a problem for people new to bullet.

I successfully created a static triangle mesh world that is synchronized with the drawn polygons. I also added random boxes that fall and properly collide with each other and the level. Now I'm trying to add the player controlled (and AI controlled) character movement.

The character will be in a 2D platform world rendered in 3D. Things like ragdolls and just about everything will be in the 3d world, while character movement and items falling on the ground will be in the 2D plane. The 3D part is for looks.

So the character will need to walk on sloped terrain, or just move left and right while in the air, and jump.

Basically my first idea was to use a dynamic body and give it impulses to move around but the fact that a body, even with 0 restitution, still bounces a little is unacceptable. Also the body slides around when landing. Setting friction super high prevents that, but then I have to do dirty hacks (well it feels dirty) and set the friction to lower so the character can actually walk on terrain instead of be forced to stand still.

So then I realized, yeah, now I believe everyone when they say to use Kinematic bodies for animated characters. The problem with this is that I have to do collision detection manually. I wrote character movement physics for my character without bullet, and am trying to reimplement those same physics but use Bullet's collision detection functions instead of using the ones I wrote, since mine are buggy about 1% of the time, and I feel like it's pointless to reimplement collision detection when I'm using a library that does it already. I'm having a hard time finding the functions I need.

My character is a capsule shape, and needs to detect collision with a static triangle mesh world. I need to do things like detect if when moving in a direction, what is the distance until collision. I also need to know the normal of the contact point so I know the steepness of the slope the character is standing on and if he's on the ground. I looked at some articles on the wiki and didn't find actual useful collision checking queries.

I'm also a little confused as to how to properly have the character collide with things like boxes or whatever else is affected by physics. Normally the kinematic body collides with something and pushes it. But what about the case where the character pushes a box, but the box is against the wall. The character should not have moved in that direction in the first place since the box should block his movement. Having a character controlled by the physics engine would solve that problem, but would a kinematic body character have code to do that manually?

Also I can't seem to find setters for collision shape. I would want my character to crouch and I want to set his capsule to a shorter capsule for crouching. I'm guessing that if I do a transform on a capsule used for a standing character and shrink it for crouching, it will warp the round ends. That way a character who is crouching on a slope will suddenly have his collision shape bounds inside the wall which is bad. Or am I incorrect in thinking this and its actually safe to do a transform on a capsule to shorten it.



Also this isn't exactly needed yet but will be needed later along the road. I would like to have a character's legs be positioned correctly with inverse kinematics depending on the slope he is on. I did some searching and it looks like there are no inverse kinematics built into bullet. Now I'm wondering, how well would it work if I took the ragdoll legs of a character and set the position of the foot and constrained the rest of the leg joints to be at certain angles. Would the ragdoll physics be able to properly position the leg or will I need to write my own IK code for that?
DragonGeo2
Posts: 16
Joined: Sat Dec 18, 2010 1:30 am

Re: Tips on character movement

Post by DragonGeo2 »

You can use the SetCollisionShape function to change an object's shape at run-time for crouching. Also, you should look into the functions:
btCollisionWorld::convexSweepTest
btCollisionWorld::rayTest
Both of those return the hit distance (called the "fraction") and a hit normal and hit position.