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)
Hand Holding
Re: Hand Holding
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
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
-
- Posts: 4
- Joined: Tue Jan 09, 2018 5:09 pm
Re: Hand Holding
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?
Re: Hand Holding
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
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
-
- Posts: 4
- Joined: Tue Jan 09, 2018 5:09 pm
Re: Hand Holding
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?
-
- Posts: 4
- Joined: Tue Jan 09, 2018 5:09 pm
Re: Hand Holding
It looks like the setWorldPosition is in character space based on some testing. I think I have everything I need now, thanks so much!
Re: Hand Holding
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
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
Re: Hand Holding
Update: Actually I will be adding built in IK functionality for the Unity Plugin soon! So subscribe to the GitHub changes for updates.
Cheers
Cheers