How to make crouching. Change collision shape on the fly?

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

How to make crouching. Change collision shape on the fly?

Post by ill »

I'm using a capsule as a collision shape for my game character.

I thought it would be pretty straight forward to just on the fly switch between two capsules which are different heights. I can't seem to find a function that allows to set a collision shape on the fly and can't find anything on Google.

Is there some way to change the height of a capsule without warping the rounded bottom edges with a scale transform?
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: How to make crouching. Change collision shape on the fl

Post by sparkprime »

Everything in my engine is a compound (even simple cubes) so I just move stuff around within the compound in order to change its shape. For removing parts entirely I have to reset the pairs.

world->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(body->getBroadphaseHandle(), world->getDispatcher());

You may just be able to change the parameters of your capsule and then perhaps reset various things that might depend on the shape.

You can always remove it from the collision world and put it back in again. This is not usually as intrusive as it sounds.
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm
Contact:

Re: How to make crouching. Change collision shape on the fl

Post by winspear »

Another cool idea would be to use two capsules joined together by a translation joint. Then when you want to crouch, you can just slide the upper capsule down by applying force. You can also get some good bounciness from your character during jumping when implemented this way.
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: How to make crouching. Change collision shape on the fl

Post by lulzfish »

I would give this guy a quick try before anything complex:

http://bulletphysics.com/Bullet/BulletF ... e5051e1a5a

btCollisionObject is a superclass of btRigidBody, so this function is available to all btRigidBodies.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: How to make crouching. Change collision shape on the fl

Post by sparkprime »

winspear wrote:Another cool idea would be to use two capsules joined together by a translation joint. Then when you want to crouch, you can just slide the upper capsule down by applying force. You can also get some good bounciness from your character during jumping when implemented this way.
You would rather want to put them in a compound so that they are locked tightly together instead of being subject to the whims of the constraint solver.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: How to make crouching. Change collision shape on the fl

Post by Flix »

Another approach I would try is a btMultiSphereShape with 2 spheres (i.e. equal to a btCapsuleShape). When crouching, the upper sphere can be moved down.
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: How to make crouching. Change collision shape on the fly?

Post by avithohol »

I know its old but in case somebody come across.

This works for me:

rigidBody->getCollisionShape()->setLocalScaling(btVector3(1,0.5,1));

This scale my body's capsule shape half sized on the Y axis.
Post Reply