ConfigurableJoint Anchors and nested RigidBodies

My game includes "tank" vehicles, which contain six independent tracks. Each tank has a RigidBody component. The tracks, which are children of the tank, each have their own RigidBody component as well. The tracks also each have a ConfigurableJoint which connects them to their tank.

On local tank instances, the setup works beautifully! A script attached to each track adds forces to it based upon the player's input, and the tank glides over even the roughest terrain.

On networked instances of my tank, things aren't working so well. My networking code directly alters the transform.position of the tank object to match it to it's position to it's authoritative instance on another client. Although the tank's tracks get drug over the terrain quite nicely, they begin to drift off after a while. The longer a networked tank drives around, the farther it's tracks drift away from it in random directions. It looks like some kind of rounding errors in each track's joint's anchoring calculations accumulate over time and it forgets where it was supposed to be positioned relative to it's parent tank.

I thought this would be an easy problem to solve, and I wrote the following code and attached it to each track to manually reassign the track's ConfigurableJoint anchor each physics frame:

var strtPos : Vector3;

function Start() {
    strtPos = transform.localPosition;
}

function FixedUpdate(hit : ContactPoint, collision : Collision) {
    joint.anchor = transform.InverseTransformPoint(transform.parent.TransformPoint(strtPos));	
}

Unfortunately - instead of ensuring that each track doesn't wander off, the above code sends each track careening off into the sunset almost immediatley.

You can witness this behavior firsthand in the latest test build of my game: http://dat.marsxplr.com/213/play Start two game instances and connect them to each other, switch to a tank in both, drive around for a bit in one, and then drive near your first tank with the other. The longer you drive around, the more messed up your tracks will look on other networked clients. (note that tracks on distant tanks aren't simulated, you need to drive near a tank to see it's "real" rigidbody tracks).

Please let me know what could be causing the joint anchoring issue in the first place, and what I can do to circumvent it!

Problem solved!

When the GameObjects that ConfigurableJoints are components of are disabled and later re-enabled, the joints get totally messed up.

This code solves it:

function Start() {
    strtPos = transform.localPosition;
}

function OnEnable () {
    if(strtPos == Vector3.zero) return;
    transform.localPosition = strtPos;
    transform.localRotation = Quaternion.identity;
    joint.anchor = Vector3.zero;
}

Hi,

First off, your backend looks to operate beautifully, with a lot of features without a lot of system overhead (for the most part). However, I wasn't able to see how to instantiate the tank objects (I saw the options to enable tanks, though), so I couldn't examine your problem. It sounds from your description that the configurable joint is being displaced during the authoritative update. Have you tried using rigidbody.MovePosition() instead of altering transform.position (since you are using a huge amount of physics)?

-CJ