Getting rid of wobbling after bonding two bodies together

Topics: User Forum
Nov 30, 2012 at 3:39 PM

Hi all.

I'm currently working on a ledge-grabbing mechanic for the platformer I'm in the midst of developing.  The basics are there - I'm following the box-and-wheel method for handling character movement and I've attached some 'grab sensors' to the sides of the player object in a similar manner using weld joints.  When either of those grab sensors collide with a ledge point defined by the map geometry (a static body), I bond the two bodies together using a weld joint and break the joint when the player wants to let go of the ledge.  This works fine.

The problem I'm facing is that there is often some 'springing' immediately after the two bodies are attached.  And sometimes during the attachment, without any input from the player, there's some wobbling / springing.  I'd prefer to have the two bodies bind together as if they were a solid object (no movement, no rotation) and I'm unsure on what properties I have to tweak in order to do this.

Not sure if I've described the problem well enough, so if anyone requests additional details I'll post a video of the problem later tonight or tomorrow.  Thanks in advance.

Coordinator
Dec 1, 2012 at 1:05 AM

The problem you are having is probably caused by the WeldJoint. It is a soft joint, so it will move under pressure (force) and if the anchor points of the joint are just a little far from each other, it will cause the bodies to snap with a little springing effect.

To make 2 objects completely as 1, you need to attach the shape of the body you grab, to the body that grabs it. Basically you remove the body you grab and attach the shape it had, to the body that grabs it. That will make the shapes immoveable relative to each other.

Dec 3, 2012 at 4:13 PM

Sounds simple enough, but I have a couple other questions...  This is probably just due to a lack of understanding of the inner workings of the library on my part, but attaching the bodies via the method you described will still work if the grab point is a static object (the player will remain bound to the grab point without moving)?  If the grab point is attached to a moving platform (the player will move with the platform)?

Thanks again.

Coordinator
Dec 6, 2012 at 11:34 PM

Bodies are the parts that move, and one body can only be dynamic or static, not both. The solution I provided will only work with dynamic bodies.

If your moving platform is static, then you might want to consider using a joint with a motor instead. If you need something like the moving platforms in Mario, use a prismatic joint. That will allow you to attach a joint between the player and the moving platform to make him hold on. Try using a revolute or weld joint to attach the player - if you need to joint to be more stable, take a look at the FrequencyHz property on the joint, and/or increase the number of position and velocity iterations inside Settings.cs.