Hi!

Lets say I have a Creature Character of a front facing guy that is doing all kinds of exercises. I have all kinds of cool animations defined, and these result in his head to be moved up, down, left and right as well as angled to the left and right.

Now I have another Creature Character, maybe of a Hat. This creature animation is also its own full character with cool animations that all the kids love.

I want to be able to take the "Hat" and "Pin" it to the "Head" component of the front facing guy. This way as he does his workout and tilts his head like a puppy, the hat will angle and translate like a boss. At the same time, the Hat can still do its own "Hat Animations" (hard pressed to think of one, maybe it stretches its cute little hat arms). As the hat does his animations, I want it to respect the angle of the head that he is "Pinned" to.

Wow, seems pretty easy! I feel like I can just set a "Vertex Attachment" in the animation then every tick just move the hat to that position. Yaaaaay that works, but the hat is not angling when the head tilts, but is does respect the translation.

I am currently working in Unity, but I don't care what runtime as long as it works. Is there someone out there who knows this answer?

Your animated hat wearing mofo wermfood!

## How can I "Pin" one Creature to another one?

### Re: How can I "Pin" one Creature to another one?

Hello,

The easiest way is to put a few more bones on your base/source character, get the world transform from the bone you care about ( for "pinning ), then use it to transform/drive the other character.

You can either do this via the creature runtimes ( look at the API calls that allow you to extract a bone transform ) or even easier, you can export out the character as a FBX character, import into Unity and use the bone transforms for that instead. Either way this should be the direction you can try.

Your other more complicated ( but accurate ) option requires you to be comfortable with the concepts of matrices/vectors in Game Engines:

1) Pick 3 vertex attachment points A, B, C ( forms a triangle )

2) Pick any of the edges for the 1st vector, call it Vector1 = normalized(A - B)

2) Compute normal of Triangle, call it Vector2 = normalized((A - B) ^ ( A - C)) where ^ is the cross product

3) Compute binormal: Vector3 = Vector1 ^ Vector2

Now you have Vector1, Vector2, Vector3 forming an orthonormal basis/orientation frame. That will allow you to form a rotational matrix ( look up tutorials on how to do this, it is quite easy ). With that, you can use the rotational matrix to pose whatever you want to pin.

Thanks

The easiest way is to put a few more bones on your base/source character, get the world transform from the bone you care about ( for "pinning ), then use it to transform/drive the other character.

You can either do this via the creature runtimes ( look at the API calls that allow you to extract a bone transform ) or even easier, you can export out the character as a FBX character, import into Unity and use the bone transforms for that instead. Either way this should be the direction you can try.

Your other more complicated ( but accurate ) option requires you to be comfortable with the concepts of matrices/vectors in Game Engines:

1) Pick 3 vertex attachment points A, B, C ( forms a triangle )

2) Pick any of the edges for the 1st vector, call it Vector1 = normalized(A - B)

2) Compute normal of Triangle, call it Vector2 = normalized((A - B) ^ ( A - C)) where ^ is the cross product

3) Compute binormal: Vector3 = Vector1 ^ Vector2

Now you have Vector1, Vector2, Vector3 forming an orthonormal basis/orientation frame. That will allow you to form a rotational matrix ( look up tutorials on how to do this, it is quite easy ). With that, you can use the rotational matrix to pose whatever you want to pin.

Thanks

### Re: How can I "Pin" one Creature to another one?

Thanks! Just to make sure I am following, here is what I understand you are telling me.

In the Exercising guy since I care about his head angle and position I would drag an extra bone across his head and call it something like HEAD_ANGLE_HORIZONTAL. Do another one up and down and call it HEAD_ANGLE_VERTICLE bone. Then extract that out the character and import it into Unity.

In the controller, during the tick/update I should pull just the HEAD_ANGLE_* bones using the GetBoneStartPt()?/GetBoneEndPt()? process. I guess these would only retrieve the point, so maybe there is another call that will do the entire bone where I can retrieve its rotation as part of this transform. Ill take a look at the API to determine how to achieve that.

While I am goofing with it, since I know how to create the Vertex Animations Ill create three Vertex Attachments on the head. A Top and two base of the head that form a triangle. At least this way, I can have some numbers to "math" and see if I can get the angle going.

Ill work on this a bit and let you know! Thanks again for responding so quickly, I really appreciate it. I just moved from Spriter to Creature, and the meshes look great, but are a bit more of a challenge for a hobbyist like myself!

In the Exercising guy since I care about his head angle and position I would drag an extra bone across his head and call it something like HEAD_ANGLE_HORIZONTAL. Do another one up and down and call it HEAD_ANGLE_VERTICLE bone. Then extract that out the character and import it into Unity.

In the controller, during the tick/update I should pull just the HEAD_ANGLE_* bones using the GetBoneStartPt()?/GetBoneEndPt()? process. I guess these would only retrieve the point, so maybe there is another call that will do the entire bone where I can retrieve its rotation as part of this transform. Ill take a look at the API to determine how to achieve that.

While I am goofing with it, since I know how to create the Vertex Animations Ill create three Vertex Attachments on the head. A Top and two base of the head that form a triangle. At least this way, I can have some numbers to "math" and see if I can get the angle going.

Ill work on this a bit and let you know! Thanks again for responding so quickly, I really appreciate it. I just moved from Spriter to Creature, and the meshes look great, but are a bit more of a challenge for a hobbyist like myself!

### Re: How can I "Pin" one Creature to another one?

Hello,

After you grab both the End and Start points, you subtract them to get a Vector. This already gives you a tangent direction to align your attachments.

You can then proceed to solve this in multiple ways. Since this is just in 2D ( assuming you are in 2D ), then it's simply the angle of the direction of the Vector of the bone direction you just determined. There are many resources/ways to do this, you can check out these writeups to get started:

http://www.davdata.nl/math/vectdirection.html

https://www.jwwalker.com/pages/angle-be ... ctors.html

After you grab both the End and Start points, you subtract them to get a Vector. This already gives you a tangent direction to align your attachments.

You can then proceed to solve this in multiple ways. Since this is just in 2D ( assuming you are in 2D ), then it's simply the angle of the direction of the Vector of the bone direction you just determined. There are many resources/ways to do this, you can check out these writeups to get started:

http://www.davdata.nl/math/vectdirection.html

https://www.jwwalker.com/pages/angle-be ... ctors.html

### Re: How can I "Pin" one Creature to another one?

It worked thanks again! I appreciate your guidance. I put the bone across the head and then calculate the angle while it leans using the formula you specified. Now I can "Pin" one creature object to another.