Character collision with bullet (impossible right now?)

Jayzen
Posts: 5
Joined: Thu Oct 11, 2007 7:39 pm

Character collision with bullet (impossible right now?)

Post by Jayzen »

I've spent a few days trying to see if I could leverage bullet to do player character collision. You know the basic non-physics stuff: instant start and stop, instant turning, sliding along walls.

I've tried a few different approaches based on comments on these forums, but they all have issues I can't seem to resolve. If anyone else out there has got this working, maybe you can help me solve some of these issues.

Here are the things I tried and the problems I ran into:

1) Player as rigid body. I set up the player as a capsule and like the manual says I set the angular force to 0. I move him around via impulses. This works okay, except that I couldn't figure out a way to make the turning be instant (so if you are going one way then spin around quickly you would slide a bit in the old direction). Also you would "bounce" off walls a bit, I couldn't get a nice sliding feeling set up.

2) Kinematic body, using the collision system to get contact points/penetration then "fixing" the position. This idea seemed to have promise but I couldn't figure out a way to ensure the player is in a valid non-colliding position in the case of many collisions happening. Worked great in the case of a single wall the player was colliding against, but as soon as he hit a corner the first position fix would push him through the other wall.

3) Kinematic body, using objectQuerySingle to determine first point of contact and modifying velocity, then running it again, then again, etc etc until no more collision. This had promise until I tried a static triangle mesh. It looks like objectQuerySingle isn't fully implemented for a triangle mesh and falls back to simple ray cast. This method seems like it would be the best, both in terms of processing power required and robustness.

If anyone has any suggestions or success stories with a different approach I'd love to hear it. Bullet works great, I'd hate to have to write a whole new system just for player collision with bullet alredy integrated and working in our program.

Thanks,

Jason Zisk
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Character collision with bullet (impossible right now?)

Post by pico »

Jayzen wrote: 1) Player as rigid body. I set up the player as a capsule and like the manual says I set the angular force to 0. I move him around via impulses. This works okay, except that I couldn't figure out a way to make the turning be instant (so if you are going one way then spin around quickly you would slide a bit in the old direction). Also you would "bounce" off walls a bit, I couldn't get a nice sliding feeling set up.
Regarding 'instant turning':
Have you already tried to apply a force with opposite velocity?
Or have you tried to setLinearVelocity to zero?

Instead of using impulses i would recommend to use setLinearVelocity for a player character.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Character collision with bullet (impossible right now?)

Post by Erwin Coumans »

This had promise until I tried a static triangle mesh. It looks like objectQuerySingle isn't fully implemented for a triangle mesh and falls back to simple ray cast. This method seems like it would be the best, both in terms of processing power required and robustness.
This should be straigtforward to enable, and perform a convex cast against the trianglemesh, instead of raycast. I will look into it and fix it for next (Bullet 2.64) version.

Bullet needs a character controller demo, so if you have any contribution in this area it would help. We can gradually improve this together.

Thanks,
Erwin
Jayzen
Posts: 5
Joined: Thu Oct 11, 2007 7:39 pm

Re: Character collision with bullet (impossible right now?)

Post by Jayzen »

pico wrote:Instead of using impulses i would recommend to use setLinearVelocity for a player character.
Thanks for the suggestion! That fixes the motion issues nicely. The collision still feels too "bouncy" though. Even when standing completely still the player kind of jitters up and down, I'm guessing because he's continually bouncing off the ground due to gravity. Is there a way to reduce this? I tried setDamping but that didn't seem to affect it.

Thanks,

Jason Zisk
Jayzen
Posts: 5
Joined: Thu Oct 11, 2007 7:39 pm

Re: Character collision with bullet (impossible right now?)

Post by Jayzen »

Erwin Coumans wrote: This should be straigtforward to enable, and perform a convex cast against the trianglemesh, instead of raycast. I will look into it and fix it for next (Bullet 2.64) version.
This would be great! That really seems to be the only thing necessary to get a nice character controller system working. If you'd like, you can share that code with me before the official 2.64 release, then I can do the player velocity part. Maybe we can get a character controller demo done for 2.64.

Thanks,

- Jason Zisk
Kot
Posts: 2
Joined: Sun Nov 25, 2007 12:33 pm

Re: Character collision with bullet (impossible right now?)

Post by Kot »

Hi!
I've been trying to simulate character movement by capsule and setting linear velocity, however I still have got one problem. When the movement key is pressed I do something like that:
rigidBody->setLinearVelocity( forwardVector * forwardFactor + leftVector * leftFactor )
It works very well when the object is on solid ground, but when its free falling, pressing the movement keys freezes the object midair (because its setting y velocity to 0). Of course I could raytrace from object to ground to test if it is standing on solid, but I want to control it in midair too, so I need a method to set only the x and z velocity components. I've tried to do:
rigidBody->setLinearVelocity( **as above** + rigidBody->getLinearVelocity().y() * Vector(0, -1, 0) )
But it drops y acceleration to zero and the object isn't really free falling.

Is the only way to solve my problem using impulses? I wouldn't like to do so, because it gave me strange results, while setting linear velocity was (almost) perfect.
Hamstray
Posts: 15
Joined: Thu Jan 11, 2007 7:45 pm

Re: Character collision with bullet (impossible right now?)

Post by Hamstray »

shouldn't that be

Code: Select all

rigidBody->setLinearVelocity( **as above** + rigidBody->getLinearVelocity().y() * Vector(0, 1, 0) )
Kot
Posts: 2
Joined: Sun Nov 25, 2007 12:33 pm

Re: Character collision with bullet (impossible right now?)

Post by Kot »

Thanks for pointing that! I feel so stupid now :oops: