Syncing Objects' Positions (Including Children)

I want to syncing the same objects positions.

For instance I have a rigged character, which moves, via user input (the kinect to be exact). Now I can’t simply attach the same script to a duplicate of the rigged character, but my suggested solution was to get all the child components (Transforms) from all the children of the rig (i.e. legs, head, arms etc) and then pass this into an array and then set the current transform (the duplicated character) to these positions. However, I can’t get it to work. Any ideas?

function Update () 
{
    var positions : Transform[]= GameObject.FindWithTag("Player1").GetComponentsInChildren(Transform).position;

    for(var pos : Transform in positions)
    {
        pos.position += Vector3.up * 0.1f;
    }

    for (var child : Transform in transform) 
    {
        child.position += Vector3.up * 0.1f;
    }
}

My code thus far. It would be nice to know the C# alternative, if anyone knows :slight_smile: Thanks.

I’m not 100% I understand you but…

If you’re saying what I think you’re saying, and what it looks like you’re saying in your code… you want the entire rigged character to move ‘up’?
(or some other arbitrary direction)

In this case, just move the root transform, on the root gameobject. And you’ll be happy.

If that’s not what you’re saying, could could also be saying that you’re looking to modify your skeleton at runtime.

In which case, if you’re playing an animation this isn’t going to work (it’ll spring back to it’s assigned position) - however you can modify an animating skeleton at runtime if you put your code in the LateUpdate(){} loop.

Game, set, match.

-JFFM

Not quite I want my rigged character to copy an exact version of itself.

For instance if I have player1 and player1copy. I want to iterate through all the transforms of player1 (i.e. legs positions, arms positions etc) and then set all there various parts (i.e. arms, legs) to player1copy’s arms and leg positions. Thus, perfectly mimicking the original player 1 rig.

The way I thought I’d do this was to copy all player1’s transform’s into an array, and then set it to all of player1copy’s transforms from the array. However, I was having trouble with this! Any help would be much appreciated :slight_smile:

Ohhhhh.

Interesting.

Just off the top of my head, I believe you’d have to do a deep copy on the Transforms - instead of saying something like:

player1copyBone.transform = player1Bone.transform;

you’d have to say:

player1copyBone.transform.rotation = player1Bone.transform.rotation;
player1copyBone.transform.localScale = player1Bone.transform.localScale;
player1copyBone.transform.position = player1Bone.transform.position + thePositionOffsetYouWant;

But even then, I’m not 100% that that will achieve everything you want.

Godspeed!

-JFFM

There’s an example of this in the 3d platformer tutorial, when it spawns a ragdoll to replace the robot.