Weld Joint Problem With Rotating Body

General discussion about Box2D tutorials
Post Reply
ptc79
Posts: 11
Joined: Tue Apr 02, 2013 9:45 pm

Weld Joint Problem With Rotating Body

Post by ptc79 » Fri Mar 14, 2014 11:05 am

Hi iforce,
I'm trying to set up a Box2D program with one circular rotating body, and another circular body that moves towards it and sticks to the first body's edge. The problem I'm having is that after I create a weld joint between the bodies, the second body tends to jump around erratically before the joint resolves itself.

The first body is a dynamic body with a circle fixture, connected to a static body with no fixtures by a revolute joint. It is able to rotate freely but not change position. The second body also has a circle fixture, and can move position freely. I use a b2ContactListener subclass to check for the collision. Then add a weld joint between the bodies, at the second body's centre, in the timestep immediately following the collision. The second body then jumps around for a few frames before the joint resolves itself at the correct position.

If I use a distance joint I don't get this problem. However, that means that the second body is able to spin on the first bodies edge. I want the second body to be in a fixed rotation relative to the first body, so I have to use a weld joint. Any ideas how I can solve this problem? Thanks for reading this.

Cheers

ptc79
Posts: 11
Joined: Tue Apr 02, 2013 9:45 pm

Re: Weld Joint Problem With Rotating Body

Post by ptc79 » Fri Mar 14, 2014 11:14 am

By the way, this effect is most obvious when the first body is rotating before the collision. This causes the second body to be in completely the wrong position after a weld joint is added. If the first body is not rotating the second body might just be a little bit off after the collision.

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Weld Joint Problem With Rotating Body

Post by iforce2d » Fri Mar 14, 2014 4:10 pm

Unfortunately weld joints are not very reliable, especially where any kind of speed or movement (and especially sudden changes thereof) are involved. To get a really solid connection would require a single rigid body, ie. move the fixture of the second body onto the first body, and get rid of the second body.

Did you try using a second distance joint to prevent the rotation of the second body?

ptc79
Posts: 11
Joined: Tue Apr 02, 2013 9:45 pm

Re: Weld Joint Problem With Rotating Body

Post by ptc79 » Tue Mar 18, 2014 12:45 am

Thanks for the help. I used a couple of Revolute joints instead. That achieved the effect I was looking for. I should have thought of that before.

Post Reply