b0gd4n wrote:I use
Code:
hinge->enableAngularMotor(true, 0, 1);
to stop the rotation.
And I assume I could use the same method to rotate it.
Please let me know if I am doing this the wrong way or something!
Yes, all the constaints have limits and motors.
1) Limits are used to limit the constraint (in your case you have a lower and an upper angular limit). In some constraints (like the btHingeConstraint) you can set the axis free by setting the upper limit smaller than the lower limit. You can lock all the constraints by setting the lower limit equal to the upper limit, and you can limit the constraint range by setting the lower limit smaller than the upper limit.
So, by using limits only, you should be able to lock and release the angular motion of your turret.
2) Motors are used to move the constraint: the direction and velocity of the move are determined by the sign and the absolute value of the motor "target velocity". The max motor force is the force needed to apply the target velocity to the constraint (I sometimes make it proportional to the object mass): if it's too low, no move will happen because the body is too heavy to move; if too big, the movement can be too rough, as the target velocity will be applied instantaneously. When both limits and motors are used, the constraint will eventually "stop" at the limit (lower or upper depending on the sign of the target velocity), but the motor will still be active. Last thing: please remember that the bodies can still go to sleep, even if there are constraints or motors applied to them (sleeping depends on the properties you apply to the rigid bodies: you can use btRigidBody->activate() to wake up a sleeping body).
Please note that there are 2 ways to lock a constraint in a particular position:
a) Don't use motors and set the two limits equal to your locked position (pro: no motor used (performance?); cons: you have to remember the true limits and re-set them before applying a motor).
b) Using a motor with a target velocity of 0 (but a max motor force >0). This way you can set the constraint limits once (if you don't need to change them).
In your case I suggest for example:
1) You leave the btHingeConstraint free to rotate (lowerLimit>upperLimit), or set the correct lower and upper limit according to your needs.
2) You apply a motor with 0 target velocity to lock the turret (choose a good max motor force and never change it).
3) when the right or left keys are down, you change the sign and modulo of the target velocity.
4) when the right or left keys are up, you set the target velocity to zero to lock the rotation again.
Please note that in some constraints you have access to single motor variables individually, but in other you must call something like: enableMotor(true,velocity,force), even if you just want to update the target velocity only.