I have an issue where I'm using a hinge constraint to connect two objects together (pretty much like a turret's attached to a tank) and it's preserving the parent's motion, as in, if I activate the constraint's angular motor while the parent object's rotating, the target object rotates slower than if the parent was stationary.
I'm creating the constraint using the following code:
Code: Select all
btVector3 axis{ 0.f, 1.f, 0.f };
btVector3 pivot{ 0.f, 0.f, -5.f };
auto* constraint = new btHingeConstraint(parentBody, targetBody, pivot, btVector3(0.f, 0.f, 0.f), axis, axis);
constraint->setLimit(-0.78f, 0.78f); // roughly [-45;45] degrees
constraint->enableAngularMotor(true, 0.f, 0.8f); // lock the motor initially
.....
// Later on, when I want it to rotate, called on every tick
constraint->setMotorTarget(btRadians(targetAngle), 0.1f);
Is there any way to make the constraint motor rotate at the same speed, independent of the parent's rotation? I've thought about negating the rotation from the parent in the constraint but I imagine there's a cleaner way to do this.