creating component doesn't work properly

I have two rigidbodies, one kinematic, which are connected by a FixedJoint. During certain times, I need to Destroy the FixedJoint component, translate the kinematic rb, and then create the joint component again, but when i do this in the fixedUpdate the joint completely fails to work.
What else can I try?

My goal here is to have the non-kinematic rigidbody rotate exactly around the kinematic ones center as it rotates, but I dont want the joint to work for a moment as I alter the relative positions between them

Instead of destroying the joint and creating a new one, could you just set its “enabled” property to false, and then back to true?

Joints don’t actually have the .enabled field. In fact I don’t think any of the physics (or physics2d) stuff can be turned off that way.

One way for OP to accomplish what he’s trying to do with a fixed joint is just to parent the objects one to another, or to parent them both to a common object that has the rigidbody on it. Not sure what OP’s intended use case is.

The use case is really complicated, unfortunately. It involves VR controllers which pull virtual hands around, which pull the player, which contains the hands. It’s so close to working, I thought this was the final bit :confused:
i assume that there’s something fundamentally wrong with destroying and recreating the joint each update because rigidbody motion has stopped, even though there are AddForce() calls from other locations.

Huh. I assumed that all components had that checkbox, but apparently there is a specific subclass purely for adding that checkbox and some things don’t inherit from it. Weird. I stand corrected.

Wait. Are you destroying and recreating it in the same frame? And in multiple consecutive frames? That seems unlikely to be a good idea.

I assumed you were disabling it for a while (at least a few consecutive frames) and then enabling it for a while. If you need to tweak it on a frame-by-frame basis, then I’d guess you probably shouldn’t be using it at all, and should instead write a new component that does what you actually need it to do without continuous destruction and recreation.

That said…I’ve done very little physics-based stuff personally (I mostly work in UI). So I guess take that with a pinch of salt.

1 Like

What I want is something like a fixed joint, but only works for rotation, allowing the radius of the rotation to vary with other physics calculations.
I think I’ve solved it now with a mix of transform.rotateAround and rigidbody.addforce but the docs recommend not mixing transform changes with physics :confused: