Making joint aim in the same direction as the main camera, regardless of joint axis

Hello

I’m trying to make a ConfigurableJoint aim in the same direction the camera is aiming in regardless of it’s axis or rotation.

My setup is a main rigidbody with a joint connecting it and another rigidbody.

The joint can be configured in any number of ways, i.e It can be acting as a hinge, or it can be acting as a wheel type joint, depending on what the axis is configured as.

I want to make it so that the joint, no matter how it’s configured or how the “main body” is rotated, always tries to match it’s forward rotation to the camera’s forward rotation.

I’ve tried some simple math code like
joint.TargetRotation = Quaternion.LookRotation(Camera.main.transform.forward,joint.axis)
but it’s not giving me the result I want, and I assume it’s not going to be as simple as that :stuck_out_tongue:

Any ideas on how best to approach this? I’m not a math expert so I feel like that’s what i’m missing.

Thanks in advance!

Physx implementation in unity3d is very poor and configurable joint is best example of it.
Let me tell you - you will probably not be able to pull it off.

TargetRotation is in joint space, joint space is in physx right-handed coordinates, to make things worst you have to take into account that you can set primary and secondary axis for a configurable joint.

Ugh, that’s unfortunate :confused:

Any ideas for a workaround, or at least how to do it without a joint and instead using transform.rotation?

With transforms you can probably do it using LookAt method.