Hello,
I tried something similar, but could not get the spring effect to work as far as it was attached directly to a static body. Finally instead of making a static rigid body for the spring attachment, I created a normal rigid body, and "pinned" it, so that it can not move, using a btGeneric6DofConstraint with all 6 dof-s locked, something like this:
Code: Select all
btTransform localA, localB;
...
btRigidBody *capsuleBody1 = localCreateRigidBody( btScalar( 1 ), offsetTransform * capsuleTransform, capsuleShape );
...
localB.setIdentity();
btGeneric6DofConstraint *joint0 = new btGeneric6DofConstraint( *capsuleBody1, localB, false );
m_dynamicsWorld->addConstraint( joint0, true );
...
btRigidBody *capsuleBody2 = localCreateRigidBody( btScalar(100.), offsetTransform * parentEndTransform * ownTransform * capsuleTransform, capsuleShape );
...
btGeneric6DofSpringConstraint *joint1 = new btGeneric6DofSpringConstraint( *capsuleBody1, *capsuleBody2, localA, localB, true );
joint1->setAngularLowerLimit( btVector3( 1, 1, 1 ) );
joint1->setAngularUpperLimit( btVector3( -1, -1, -1 ) );
joint1->enableSpring( 0, true );
joint1->enableSpring( 1, true );
joint1->enableSpring( 2, true );
joint1->setStiffness( 0, 20.f );
joint1->setStiffness( 1, 20.f );
joint1->setStiffness( 2, 20.f );
m_dynamicsWorld->addConstraint( joint1, true );
Here capsuleBody1 was originally a static rigid body. Now it is a normal rigid body"fixed" by joint0.
I know it does not answer the original question, but it might help.