Constrained Object Movement

Post Reply
Kadesh
Posts: 4
Joined: Fri Aug 08, 2014 7:34 pm

Constrained Object Movement

Post by Kadesh »

I'm creating two rigid bodies and then setting a hinge constraint with pivot = (0,0,0) for one of them and then moving the other body. I thought this meant that the object with the non-zero pivot would essentially act as an anchor for the other one, without having its movement affected by it.
However, if I apply an impulse to the parent body, its movement is affected by the child object.

For example:

Code: Select all

// with:
body_A_mass = 1
body_B_mass = 150
body_A_pos = (30, -15, 0)
body_B_pos = (0, -5, 0)
body_A_pivot = (0, 0, 0)
body_B_pivot = (30, -10, 0)
axis = (0, 1, 0)

// if I do the following, I can then see the position vary slightly over time in the Y axis rather than just X
body_B->SetLinearVelocity(30, 0, 0)
Am I doing something wrong here or is there another way to create an anchored object that does not affect the parent? I've looked at fixed constraints but they seem pretty soft and also tried doing this with a reduced mass difference but it only made the issue more noticeable (since I'm guessing that the constraint effectively shifts the center of mass).

Thanks in advance for any help.

Edit: I did find a workaround, which was setting the parent body's mass extremely high but that seems very hackish.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Constrained Object Movement

Post by Basroil »

Kadesh wrote:I'm creating two rigid bodies and then setting a hinge constraint with pivot = (0,0,0) for one of them and then moving the other body. I thought this meant that the object with the non-zero pivot would essentially act as an anchor for the other one, without having its movement affected by it.
However, if I apply an impulse to the parent body, its movement is affected by the child object.

For example:

Code: Select all

// with:
body_A_mass = 1
body_B_mass = 150
body_A_pos = (30, -15, 0)
body_B_pos = (0, -5, 0)
body_A_pivot = (0, 0, 0)
body_B_pivot = (30, -10, 0)
axis = (0, 1, 0)

// if I do the following, I can then see the position vary slightly over time in the Y axis rather than just X
body_B->SetLinearVelocity(30, 0, 0)
Am I doing something wrong here or is there another way to create an anchored object that does not affect the parent? I've looked at fixed constraints but they seem pretty soft and also tried doing this with a reduced mass difference but it only made the issue more noticeable (since I'm guessing that the constraint effectively shifts the center of mass).

Thanks in advance for any help.

Edit: I did find a workaround, which was setting the parent body's mass extremely high but that seems very hackish.

1) If you want to make a door like object, just feed in the part that's moving and bullet will anchor it to the world instead of another body
2) If you want an immobile body and a constrained one, just make the first have zero mass (0 mass would blow up math so it's used for static bodies and skips the calculations)
Kadesh
Posts: 4
Joined: Fri Aug 08, 2014 7:34 pm

Re: Constrained Object Movement

Post by Kadesh »

I'm afraid neither of those options works in my case since I'm essentially trying to make a turret attached to a moving object. So ideally the turret wouldn't affect movement in any way but would still be controlled by hinge motors.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Constrained Object Movement

Post by Basroil »

Kadesh wrote:I'm afraid neither of those options works in my case since I'm essentially trying to make a turret attached to a moving object. So ideally the turret wouldn't affect movement in any way but would still be controlled by hinge motors.
Sounds like you need to decide on whether you should be using two bodies in the first place!

What you are describing is NOT a dynamic system, rather a kinematic one, and is better simulated as a single "body" with compound shape
Post Reply