[Solved] Hinge with angular motor getting stuck.

Post Reply
eplk
Posts: 8
Joined: Wed Jul 29, 2015 9:37 pm

[Solved] Hinge with angular motor getting stuck.

Post by eplk »

I have two box shapes connected via a hinge constraint (somewhat like a wall and a door). I've set the limits for the constraint to -1(lower) and 1(upper) and disabled collisions for the linked bodies.
When I enable an angular motor and let it run into the limit for more than two seconds or so and then flip the direction of the motor (targetVelocity * -1), it doesn't move anymore; it's like the hinge is stuck on the limit. If it has been running into the limit for less than two seconds before I flip the direction, the hinge just starts turning the other way as expected.
Is there a way to prevent the hinge (or angular motor) from getting stuck?
Last edited by eplk on Tue Oct 06, 2015 3:21 pm, edited 1 time in total.
eplk
Posts: 8
Joined: Wed Jul 29, 2015 9:37 pm

Re: Hinge with angular motor getting stuck.

Post by eplk »

Has anyone else ever had this problem? Is it a known issue? Is it by design? Or could I just be doing something wrong?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Hinge with angular motor getting stuck.

Post by Basroil »

Sounds like the bodies are going to sleep, did you make sure to disable deactivation?
eplk
Posts: 8
Joined: Wed Jul 29, 2015 9:37 pm

Re: Hinge with angular motor getting stuck.

Post by eplk »

Basroil wrote:Sounds like the bodies are going to sleep, did you make sure to disable deactivation?
That was it. Thank you very much!
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: [Solved] Hinge with angular motor getting stuck.

Post by drleviathan »

BTW, completely disabling deactivation might not be what, depending on what exactly you're trying to do -- an object that never deactivates can constantly wake up other objects nearby and if the hinged object is ever expected to actually come to rest then deactivation is useful. If you allow the object to be deactivated you can (1) explicitly activate the object (using btCollisionObject::activate()) right before changing any motor parameters or otherwise interacting with the object directly and (2) tune the deactivation thresholds on a per-object basis (using btRigidBody::setSleepingThresholds()) to be below whatever the minimum valid motor velocities you are expecting.
eplk
Posts: 8
Joined: Wed Jul 29, 2015 9:37 pm

Re: [Solved] Hinge with angular motor getting stuck.

Post by eplk »

Thanks for the extra info. Activating the body when changing motor parameters is exactly what I'm doing now. I find it curious though that this isn't done automatically. I can't think of a situation in which you would change the motor parameters and want the bodies to stay asleep. Am I missing something?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: [Solved] Hinge with angular motor getting stuck.

Post by Basroil »

eplk wrote:Thanks for the extra info. Activating the body when changing motor parameters is exactly what I'm doing now. I find it curious though that this isn't done automatically. I can't think of a situation in which you would change the motor parameters and want the bodies to stay asleep. Am I missing something?
Only possible one is where you accidentally do it and then switch back, but that's pretty rare if you're doing it correctly :wink:

If you want to, you can add your activation code directly to the constraint parameter functions, so if the parameters change it will do it "automatically"
Post Reply