Parenting keeping the world space position.

Parenting keeping the world space position.

manuel.spkDKCCG
Contributor Contributor
3,777 Views
7 Replies
Message 1 of 8

Parenting keeping the world space position.

manuel.spkDKCCG
Contributor
Contributor

Hi!
I need to parent a bone to a skeleton in an animation like this:

 

Captura-de-pantalla-2022-05-24-133655

 

But when I parent them both, the skeleton position becames relative to the bone, instead to world space, like this:

Captura-de-pantalla-2022-05-24-133731

 

Is there any way for parent them and keeping the world position of the animations?

Things I've tried:

    - The preseserve position in Parent Options.

    - Try playing with Matrix nodes, but I don't know exactly what I need.

 

Any help? Thanks!

0 Likes
Accepted solutions (1)
3,778 Views
7 Replies
Replies (7)
Message 2 of 8

manuel.spkDKCCG
Contributor
Contributor

Any help, please?

0 Likes
Message 3 of 8

mspeer
Consultant
Consultant

Hi!

In Parent [Options]:

Preserve position (make sure this is enabled)

0 Likes
Message 4 of 8

manuel.spkDKCCG
Contributor
Contributor

Hi Mspeer. Thanks for your help.

When I use the preserve position option, It parents the objects in the way I want, as you said. But when I change the frame, It goes to the wrong position again (relative to the parent, instead of world space)

 

As an example:

 

Captura-de-pantalla-2022-05-29-205920

- I want to parent this rig to this joint.

 

 

Captura-de-pantalla-2022-05-29-205949

- When I use the "preserve position" everything goes as desired.

 

 

Captura-de-pantalla-2022-05-29-210006

- But when I go to the next frame of the animation, the rig changes Its position relative to the joint, instead of preserving Its position.

 


Any help? I'm pretty sure this can be easily done, but I cant figure out how.
Thanks!!

0 Likes
Message 5 of 8

Kahylan
Advisor
Advisor

Hi!

 

can I ask why you need your rig to be parented to this joint?

0 Likes
Message 6 of 8

manuel.spkDKCCG
Contributor
Contributor

@Kahylan Sure! I'm trying to add a Root Motion bone to the animation. This extra bone is used in videogame engines (Unreal in my case) to drive the collision capsule along the animation path.

You can read more here: Root Motion | Unreal Engine Documentation

 

Any help will be appreciated. Thanks!

0 Likes
Message 7 of 8

Kahylan
Advisor
Advisor
Accepted solution

That was what I would have guessed, I'm just a bit confused why the Root Motion Joint isn't at the world origin (0,0,0) where RMJs normally are located, because in that case it would not cause this problem.

 

There are two easy ways to achieve what you want in Maya, but I'm not quite sure with both how well they will translate to Unreal.

 

The first one is to turn off "inherits Transfrom"  in the Attribute Editor on the joint you are parenting to your RMJ before you parent it. This will cause the joints matrix to completely ignore the RMJ, so it also won't move when the RMJ is moved.

 

The second one is to offset the Parent Offset Matrix, this solution only works in maya 2020+, the offset parent Matrix options are located right under the "inhertit Transform" option in the Attribute editor. You can Simply take your RMJs  translate values multiply them by -1 and put that value in the corresponding box in the composition Tab this will only work if the RMJ only has Translation, not with Rotation or Scale. This option will also allow you to move the entire rig by the RMJ if you wish to do so.

 

There is a method that is a bit more complex but I think the chances with this one to transfer correctly to unreal are better then the other two above. Offsetting animation. Once you have parented your rig to the new joint, you just offset back the entire animation curves on the joint right beneath your RMJ relative to the parents offset to world the origin.

Now it is important to note that this works pretty easily if the joint your RMJ only has Translations.

If that is the case I even have a script to do that. Just parent your Rig to your RMJ and select the Joint direclty under the RMJ and run this script from a python tab:

 

from maya import cmds
def offsetAnimationToParent():
    sel = mc.ls(sl = True)
    
    attributes = ["tx","ty","tz","rx","ry","rz"]
    for s in sel:
        parentObj = mc.listRelatives(sel, parent = True)[0]
        anim_changes = []
        for attr in attributes:
            ac = cmds.listConnections("{0}.{1}".format(s,attr), s = True)[0]
            if ac != None:
                v = mc.getAttr('{0}.{1}'.format(parentObj, attr))
                anim_changes.append([ac,v])
        for crv in anim_changes:  
            cmds.keyframe(crv[0], edit=True, relative=True, vc=(crv[1]*(-1)))

offsetAnimationToParent()

 

 

If your RMJ also has Rotations and Scale on it that arent default, the math behind it will get a lot harder and you'd probably have to write a script that just matches positions to a dummy object with the same animation in the same local space without inherited Transforms at every keyframe.

 

I hope this helps!

0 Likes
Message 8 of 8

manuel.spkDKCCG
Contributor
Contributor
Hi!
Thanks for the help. Finally I managed It by doing a script (basically, using locators to save the transform for each keyframe, and apply It once parented)

Thanks!
0 Likes