This project is read-only.

Creating joints conditionally

Aug 11, 2010 at 5:48 PM
Edited Aug 11, 2010 at 5:48 PM
Hello, I have a platformer in which the player is able to pick up and carry certain objects for short distances (one object at a time). I understand that one approach is to create a joint between the player and the object when the player picks it up. However, this would cause heap allocations during gameplay, and I am trying to avoid those. Is there a way to accomplish this with only one joint? For instance, at load time I would have: myJont.BodyB = inactiveDummyBody; and at run-time I would change the joint, myJoint.BodyB = pickedUpObject; Thanks
Aug 12, 2010 at 1:11 PM

You can set the joint itself as in-active when not being used.

Aug 12, 2010 at 8:37 PM
Hi blecki, Thanks for the response. However, I don't see any way to make the joint inactive, other than setting one of the bodies to be inactive. Also, I guess I would have to create a pool of joints -- one for each object that can be picked up in order to accomplish this with joints. Is this correct? Thanks
Aug 13, 2010 at 10:42 PM
Huh, looks like Joint.IsActive() just checks the attached bodies. In which case your original idea might work with a little work. You can't just change the body the joint points to. Look in World.CreateJoint; it does a lot of work maintaining various lists. I would create a version of CreateJoint that works with a joint instance you have already allocated.