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?
How to make crouching. Change collision shape on the fly?
-
- Posts: 7
- Joined: Sat Jan 29, 2011 4:14 am
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: How to make crouching. Change collision shape on the fl
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.
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.
-
- Posts: 77
- Joined: Thu Nov 26, 2009 6:32 pm
Re: How to make crouching. Change collision shape on the fl
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.
-
- Posts: 43
- Joined: Mon Jan 03, 2011 4:26 pm
Re: How to make crouching. Change collision shape on the fl
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.
http://bulletphysics.com/Bullet/BulletF ... e5051e1a5a
btCollisionObject is a superclass of btRigidBody, so this function is available to all btRigidBodies.
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: How to make crouching. Change collision shape on the fl
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.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.
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: How to make crouching. Change collision shape on the fl
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.
-
- Posts: 34
- Joined: Sun Feb 12, 2017 10:22 am
Re: How to make crouching. Change collision shape on the fly?
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.
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.