I am trying to implement this Stackoverflow answer in Bullet.
I have created a btGeneric6DofSpringConstraint with movement only on the Y axis. A kinematic body attached to the bottom and a capsule shape rigid body to the top.
Now the spring still bounces a lot even with damping set to 1 or higher. It also seems like the constraint blocks movement on the X and Z axis as applyCentralForce doesn't seem to move the capsule.
Here is the current setup:
Code: Select all
btDefaultMotionState* pMotionState;
btDefaultMotionState* pMotionState2;
btGeneric6DofSpringConstraint* pGen6DOFSpring;
btCollisionShape* capsuleShape = new btCapsuleShape(0.5, 0.5);
btCollisionShape* emptyShape = new btEmptyShape();
btVector3 inertia(0, 0, 0);
pCollisionShape->calculateLocalInertia(2, inertia);
pMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(10, 6, 10)));
pMotionState2 = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(10, 4, 10)));
pRigidBodyA = new btRigidBody(2, pMotionState, capsuleShape, inertia);
pRigidBodyB = new btRigidBody(0, pMotionState2, emptyShape, inertia);
pRigidBodyA->setActivationState(DISABLE_DEACTIVATION);
pRigidBodyB->setActivationState(DISABLE_DEACTIVATION);
pRigidBodyB->setCollisionFlags(pRigidBodyB->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
btTransform frameInA, frameInB;
frameInA = btTransform::getIdentity();
frameInA.setOrigin(btVector3(btScalar(0.), btScalar(-3.), btScalar(0.)));
frameInB = btTransform::getIdentity();
frameInB.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));
pGen6DOFSpring = new btGeneric6DofSpringConstraint(*pRigidBodyA, *pRigidBodyB, frameInA, frameInB, true);
pGen6DOFSpring->setLinearUpperLimit(btVector3(0., 3., 0.));
pGen6DOFSpring->setLinearLowerLimit(btVector3(0., 0., 0.));
pGen6DOFSpring->setAngularLowerLimit(btVector3(0.f, 0.f, 0.f));
pGen6DOFSpring->setAngularUpperLimit(btVector3(0.f, 0.f, 0.f));
pGen6DOFSpring->enableSpring(1, true);
pGen6DOFSpring->setStiffness(1, 39.478f);
pGen6DOFSpring->setDamping(1, 1.f);
pGen6DOFSpring->setEquilibriumPoint();
physics.dynamicsWorld->addRigidBody(pRigidBodyA);
physics.dynamicsWorld->addRigidBody(pRigidBodyB);
physics.dynamicsWorld->addConstraint(pGen6DOFSpring, true);