Just want to move the knight arm

Hello,
I’m experimenting with the AnimatedModel sample where there is a knight fbx model that has a well structured skeleton.Now I want to rotate knight’s arm from code.I have edited the RotateEntity.cs script and changed the code that now looks like this:
`
var modelComponent = Entity.Get();
var transformComponent = Entity.Get();
var mvhto = new ModelViewHierarchyTransformOperation(modelComponent);

            foreach (var mesh in modelComponent.Model.Meshes)
            {
                var nodeIndex = mesh.NodeIndex;

                if(mesh.Name.Contains("Arm"))
                {
                    var node1 = modelComponent.Skeleton.Nodes[nodeIndex];
                    node1.Transform.Rotation *= Quaternion.RotationY(rotationSpeed * elapsedTime); 
                    mvhto.Process(transformComponent);
                }
            }`

But the problem is that nothing is moving in the runtime. I have also tried with fixed angle,translate,different knight’s parts with no success.
Please help.Thanks.

Unfortunately, if your animation is still playing, it will overwrite any values that you set on any property that has animation.

You need to have intermediate skeleton nodes that are not animated, so that you can set them yourself without them being overridden every frame by the animation update engine.

If you don’t run or stop the animation, it works fine, right?

More complex system makes animation and physics interact with each other (they need to be aware of each other and work with advanced constraints/IK or even AI), but this is probably not what you are looking for, right?

Thanks for the answer,
The animation is not running,I have disabled it in the UIScript.cs.The knight is standing still.

I would like to control (rotate,translate) sub-parts of skeleton structured models, without the intervention of physics engine.

Sorry, thought the animation was still playing.

In that case, it should be as simple as:

var modelComponent = Entity.Get<ModelComponent>();

for (int nodeIndex = 0; nodeIndex < modelComponent.Model.Skeleton.Nodes.Length; nodeIndex++)
{
    var nodeName = modelComponent.Skeleton.Nodes[nodeIndex].Name;

    if (nodeName.Contains("Hand"))
    {
        modelComponent.Skeleton.NodeTransformations[nodeIndex].Transform.Rotation *= Quaternion.RotationX(rotationSpeed * elapsedTime * 4.0f);
    }
}

Why it didn’t work before?

  • NodeTransformations is an array of struct, which means if you make a copy in a local var (node1) of it the original won’t be modified. Things should be better in VS15 where you can do ref var node1 = .. (it will keep a reference instead of a copy, so any change you do will be reflected in NodeTransformations

  • You were moving the mesh of a skinned mesh instead of its bones. The skinning system is updating “skinning matrix” that uses bone matrix and also inverts the mesh matrix you were modifying, auto-compensating any movement (this makes sure the mesh is at the location of the bones however the artist designed the “T-Pose”). To fix this, I moved the node of the bone LeftHand and RightHand instead of the node of the mesh ch00_Knight_UpperArm_L and ch00_Knight_UpperArm_R.

Hope that helps!

1 Like

Thank you Xen2,

It’s totally working now! :slight_smile:
And thanks for a great explanation.
I was a little desperate because searching for this for few days.
Keep up the great work :thumbsup:

The Xenko Already have ik?