Runtime Video Humanoid2.mp4
In the explanation below, we expands "Humanoid.zip" and changed the name of the folder to "Humanoid2/". Open this folder with Unity.
Define the enum type "enum Bone" and declare the variable "bone" of this type as public. By writing like this, you make an item called "Bone" in the "Rig Control 3 (Script)" component displayed in the inspector window of the Unity Editior so that you can change the bone to be operated with the popup menu while executing the program.
In Unity, Bone is specified by the "HumanBodyBOnes.BoneName". Therefore, you need to define a conversion from an "enum Bone" type defined here to HumanBodyBones type in Unity. The variable bodyBones defines the mapping.
We use Enum.GetValues() function to operate on all the elements of the "enum Bone", but to use Enum we need to declare "import Syste;" at the beginning of the program.
In this program, We use the offset(float,float,float,float) method of the RigBone class to add rotation to the initial value of each Bone. The RigBone class is defined in "Assets/Scripts/RigBone.cs" in the project window.
RigControl3.cs |
|
Settings of Rig Control (Script) -> Remove Component
Select some bones and set values in this situation.
In order to set up properly I recommend the following way.
By operating like this, you can rotate the Bone with the Angle around the axis specified
in the local coordinate system of that Bone .
When BodyRotation is set to (X,Y,Z)=(0,180,0), Humanoid points to camera direction. The one who operated in this state may be easier to grasp the image.
[Notice] The Bone enumerated type defined in "RigControl3.cs" also includes "optional Bone" in Unity's Animator. Therefore, depending on the used Humanoid data, some errors may be generated at the time of execution in trying to acquire the Transform of optional Bone not assigned. In such a case, comment out the optional Bone (which are specified as "// optional") from the definitiona of the enum Bone.
"rig3.unity" has been already creaetd, so overwrite it.
File -> Save Scenes
Unity's coordinate system is left-handed. In the left-handed coordinate system, the positive rotate direction about each axis is "clockwise when looking at the origin from infinity of its axis".
Positive Rotate Direction Around Each Axis |
In each Bone, you can see the orientation of the X-axis of its local coordinate system (i.e. Transform) by increasing the value of Angle in the state of (Axis X, Axis Y, Axis Z) = (1, 0, 0). Similarly, you can see the orientation of the Y-axis in the state of (Axis X, Axis Y, Axis Z) = (0, 1, 0), and the orientation of the Z-axis in the state of (Axis X, Axis Y, Axis Z) = (0, 0, 1). The following figure shows the result of examining the axes of rotation of each bone by repeating this procedure.