Hand Holding

Discuss issues pertaining to the various game/web runtimes of Creature here.
Post Reply
jonhillman
Posts: 4
Joined: Tue Jan 09, 2018 5:09 pm

Hand Holding

Post by jonhillman » Tue Jan 09, 2018 5:16 pm

We are trying to setup a rig (in Unity) where two characters will hold hands while moving (walking, running, jumping). I've tried using the bones override callback to position the 'hand' bones, but this seems to literally only affect the hand bone, and not the 'chain' of hand -> forearm -> upper arm, and is also slightly confusing because of the use of XnaGeometry.Vector4 for bone positions (I'm not convinced I'm dealing with passing in world position correctly). I've also tried manually positioning the hand rigidbody, which has no effect at all.

How would you guys go about setting up the rig we need? The idea is that we'll have animations, some bend motors, and then sometimes two characters will hold hands, so we need to override the relevant hand/arm positions of those characters, but leave all other animations intact. Could it be the case that with bend motors setup that I could manipulate the rigidbodies and have that alter the animations appropriately? (I've tested so far with the supplied ninja character and rig)

chong
Posts: 724
Joined: Thu Feb 19, 2015 2:21 am

Re: Hand Holding

Post by chong » Tue Jan 09, 2018 11:40 pm

Hello,

In your case using the BoneOverride is the correct thing to do. However, the issue is that you are simply posing just one bone when what you actually want is the whole chain of bones.

Essentially, what you are asking for is to solve an IK problem. To solve for a general case ( > 2 bones ) is a more complicated subject in itself.

For a 2 bone case however, you can leverage something like this ( this sample has C# code in it for you to reference ):
http://www.ryanjuckett.com/programming/ ... -ik-in-2d/

You give it your target X, Y and it will give you the resulting angles you need to rotate your bones by. You get the angles and compute the 2D rotated positions using Unity's rotation functions on points. Then you apply it to the bones using the BoneOverride calls for the bones you care about.

Cheers

jonhillman
Posts: 4
Joined: Tue Jan 09, 2018 5:09 pm

Re: Hand Holding

Post by jonhillman » Wed Jan 10, 2018 3:10 pm

Great, I'll take a look, thanks for the quick response. With respect to bone position expressed as an XnaGeometry.Vector4, what is the appropriate way to pass in a world position Unity.Vector3?

chong
Posts: 724
Joined: Thu Feb 19, 2015 2:21 am

Re: Hand Holding

Post by chong » Wed Jan 10, 2018 4:28 pm

Hello,

For a Xna.Vector4, first it is a 4 vector which means the final component ( the fourth ) should be 1.
Also, your world position from Unity needs to be transformed into character space. That is you need to apply the inverse of the character's transform matrix onto it to map it into local character space. This is because all bone positions are in character space.

Cheers

jonhillman
Posts: 4
Joined: Tue Jan 09, 2018 5:09 pm

Re: Hand Holding

Post by jonhillman » Wed Jan 10, 2018 5:03 pm

Should I be setting cur_bone.setWorldEndPt and cur_bone.setWorldStartPt? That implies to me that the bone positions are world positions, and not in character space. Would I use the TransformToCreaturePt method found in CreatureGameController to go from world to character space?

jonhillman
Posts: 4
Joined: Tue Jan 09, 2018 5:09 pm

Re: Hand Holding

Post by jonhillman » Wed Jan 10, 2018 5:52 pm

It looks like the setWorldPosition is in character space based on some testing. I think I have everything I need now, thanks so much!

chong
Posts: 724
Joined: Thu Feb 19, 2015 2:21 am

Re: Hand Holding

Post by chong » Wed Jan 10, 2018 6:07 pm

Yes, it does look like I already provided you a helper function you to that ( which you found already ):
TransformToCreaturePt()

You want to call the bone's SetWorldStartPt and SetWorldEndPt() yes. "World" in the bone's context means the character world or character space.

Cheers

chong
Posts: 724
Joined: Thu Feb 19, 2015 2:21 am

Re: Hand Holding

Post by chong » Fri Jan 12, 2018 4:26 am

Update: Actually I will be adding built in IK functionality for the Unity Plugin soon! So subscribe to the GitHub changes for updates.

Cheers

Post Reply