Hinge constraint and gravity

Post Reply
Dr. DOX
Posts: 14
Joined: Sun Jul 10, 2016 11:51 am

Hinge constraint and gravity

Post 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
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Hinge constraint and gravity

Post 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.
Post Reply