Page 1 of 1

Hinge constraint and gravity

Posted: Wed Nov 09, 2016 5:45 pm
by Dr. DOX
Hi, sorry for noob question but I'm trying some test using hinge constraint. Build the constraint and set a motor velocity and impulse to reach a target angle is silly, but when I've reached this angle I have to call the enableAngularMotor(false,0,0) to stop. This one stops but it fall under gravity immediately. This is obvious, but there is a method to stay at target angle when is reached?

Many thanks, bye

Re: Hinge constraint and gravity

Posted: Wed Nov 09, 2016 11:16 pm
by benelot
Hi,

Welcome to the Bullet Physics forum! There is not such method to keep you stay on target. However, you can easily fix it by doing some PID (Proportional Integral Derivate) Control. Basically, you calculate a required velocity based on the difference between your current angle and your target angle. The more you approach your target angle, the smaller the velocity gets. Here is an example of this within the bullet example browser:
https://github.com/bulletphysics/bullet ... o.cpp#L338

This moves a spider creature's legs according to some desired target angles. Just try it out, you should quickly get some fairly accurate movement.