1

I am trying to make the skeleton to move relative to the bones that are touching the floor using animation nodes.

What I did is calculate the difference between the current and previous positions of the bones and apply the difference of the lowest bone to the root bone.

enter image description here

Here is the blend file:

Denis
  • 13,059
  • 7
  • 60
  • 81
  • Not entirely sure what you want to achieve here. Can you elaborate? What should the end result be? – Omar Emara Aug 25 '18 at 19:21
  • @OmarAhmad when the animation played, the lowest bone should stay stationary and the root bone displaced relative to the lowest. The result should be displaying actual movement of the skeleton like it is walking. – Denis Aug 25 '18 at 19:29
  • Is the "lowest" bone a fixed bone? Or is it chosen dynamically as the bone with the lowest z location? – Omar Emara Aug 25 '18 at 19:40
  • @OmarAhmad It is dynamically chosen by the lowest z location – Denis Aug 25 '18 at 19:42

1 Answers1

2

Always Touch The Floor

In this section, we shall position the root bone of the armature such that the lowest bone is touching the floor. Since the ankle/heel bone's local z axis is perpendicular to the global z axis, the head and tail z locations are identical and since the tip/tail of the toe bone will be the last bone touching the floor, to identify the lowest bone, we shall use the location of the tail instead of the head.

First, we compute the index of the bone with the lowest tail z value by using numpy's argmin() function, the input of the function should be a memory view of the values computed using the asMemoryView() method, so the expression becomes:

numpy.argmin(z.asMemoryView())

To get the minimum value itself, we simply get the value at that output index as follows:

Minimum

Now, we should move the armature along the global z axis—By moving the root bone Spine—to make the lowest bone touch the floor, this is done by subtracting the lowest z value from the z value of the root and assign the new location by using the expression:

object.pose.bones["spine"].matrix.translation = location

Set Root

The result is the lowest bone always touching the floor which concludes this section.

Touch The Floor

Root Displacement

In this section, we shall displace the armature—By displacing the root/spine bone—based on the displacement of the bone that is touching the floor, that is, the lowest bone which we know from the foregoing section. To compute the displacement of all bones, we shall use the method I described in this question. Note, however, that all bones are children of the root bone and thus any displacement in the root bone causes further displacement on all the children, so, to get the actual displacement of the bones without the displacement caused by the root, we should add the displacement of the root to the displacement of the bones. Now that we have the displacement of all bones, we can get the displacement of the lowest bone using the index we already computed in the foregoing section.

Displacement

Notice that the Get List Element node with zero index is the one that gets the the position of the root bone and the subtract gets the displacement, also notice how we add that displacement to the displacement of the bones.

Now, all we have to do is displace the root by the displacement we computed by adding it to its original position (Or subtracting depending on how we computed the displacement, which is the case here). Note that we already have the z location of the root from the foregoing section, so we just need the x and y locations. One last thing to do is reset the location of the root bone to some initial location of your choice at the initial frame, zero location for instance. This is done by checking if the current frame is the start frame and use a Switch node to switch between the current and the initial location.

Set Root Location

And the result is as you might expect.

Result Animation

Blend file for study:

Omar Emara
  • 22,639
  • 5
  • 55
  • 103
  • Currently I can't test this, but the displacement should be on the root bone instead of the armature. – Denis Aug 25 '18 at 21:20
  • @Denis By root I assume you mean the "spine" which is the parent of all bones, thus applying the transformation on the object is exactly the same as applying the transformation on the root. Am I mistaken? – Omar Emara Aug 25 '18 at 21:27
  • Yes, the displacement is applied on the spine bone. The movement of the skeleton should be inside of the Armature space, because the animation is used outside of blender where the origin of the animation is fixed. – Denis Aug 25 '18 at 21:40
  • @Denis Added another method to fit your need. – Omar Emara Aug 26 '18 at 09:08
  • This method is not going to work for me, do you think its possible fix the spine bone displacement in the node tree I created? – Denis Aug 26 '18 at 19:04
  • @Denis To be honest, your node tree is rather messy and I don't understand the point of it. Can you tell me why that method doesn't work for you? I will be able to help that way. – Omar Emara Aug 26 '18 at 19:12
  • The armature should stay at the same location, and the spine bone displaced relative to the lowest bone, the result of the example animation should be that the skeleton walking forward then sideways and returns to the original location. I cant use keyframe insert as a solution. – Denis Aug 26 '18 at 19:22