- Home /
Configurable Joint not working correctly in a moving vehicle
Hi all,
I am having an issue with joints.
I have a basic vehicle (https://i.imgur.com/KtcDho0.png) that I am trying to steer by actually turning a steering wheel (https://i.imgur.com/zE4VWke.png) mounted to an anchor (https://i.imgur.com/sbafyfZ.png) via a hinge joint. Here's the layout of the vehicle gameobject: https://i.imgur.com/vqHGLU6.png
When the arm touches the wheel, OnTriggerEnter creates a configurable joint between the arm and the steering wheel.
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("SteeringWheel")) { if (joint == null) { joint = gameObject.AddComponent<ConfigurableJoint>(); joint.connectedBody = other.gameObject.GetComponent<Rigidbody>(); joint.xMotion = ConfigurableJointMotion.Locked; joint.yMotion = ConfigurableJointMotion.Locked; joint.zMotion = ConfigurableJointMotion.Locked; Debug.Log(arm.ToString() + " attached"); } }
Here is a video of the 3 different behaviors I get from this setup: https://www.youtube.com/watch?v=ApUHp9gy0As
(0:00) occasionally the collider on the arm and the trigger on the wheel do nothing
(0:10) If I start moving the vehicle (by providing torque to the axles) and then grab the wheel usually everything works correctly
(0:26) If I grab the wheel and then start the vehicle moving, the steering wheel's rotation seems to be attached to the world instead of the car, and it rotates around world Y when I steer.
I've tried freezing the steering wheel's x and z rotations but when I do the wheel flips out and jumps all over the place. It seems like if I unlock the wheel's positions it jumps back to the position it was at when the Configurable Joint was created. Looking at the configurable joint, it seems like the joint has auto configure connected anchor checked. Do I have to manually update the connected anchor as the vehicle moves? or is something else going on?
Thanks very much!