BulletPhysics - Set hinge angle explicitly?
hingeAngle can be retrieved as a singular float but not be set explicit. I am simulating a door using hinges and need to be able to instantly set the angle to open or closed at will. How can this be achieved?
The hinge is created with:
const float mass = 10.0f; BoxShape boxShape = new BoxShape(Door.CollisionShape); Vector3 pivotA = new Vector3(-Door.CollisionShape.X, Door.CollisionShape.Y, Door.CollisionShape.Z); door.rigidBody = physics.LocalCreateRigidBody(mass, door.getRotationMatrix() * Matrix4.CreateTranslation(position), boxShape); door.rigidBody.ActivationState = ActivationState.DisableDeactivation; door.rigidBody.UserObject = "Door"; var axisA = Vector3.UnitY; // pointing upwards, aka Y-axis var hinge = new HingeConstraint(door.rigidBody, pivotA, axisA); hinge.SetLimit(-(float)Math.PI * 0.25f, 0); physics.World.AddConstraint(hinge);
and I am moving it with:
float targetVelocity = Door.OpenSpeed; float maxMotorImpulse = 1.0f; door.hinge.EnableAngularMotor(true, targetVelocity, maxMotorImpulse);
On each step BulletPhysics increases the
hingeangle based on the
targetVelocity. I'm looking to set this value directly, as opposed to indirectly by applying forces.
1 Answers BulletPhysics - Set hinge angle explicitly?
Did you try setMotorTarget() function?
void btHingeConstraint::setMotorTarget ( btScalar targetAngle, btScalar dt );
Is your desired behaviour that the door changes from open to close, in a single simulation step?
If so, that seems a dangerous thing to do, because there may be something blocking the door, and by hard-setting the door rigid body, it may be intersection other shapes.