IK is also a very magical and practical thing ah, at least you can use code to control the character bone position is still very cool. Because it's not an animator ~
This may not have anything to do with animator. Ha, it's all code-level.
Looked at an official case, the old, some problems, their own modified a bit, to achieve the effect.
The official recommendation is to place all IK operations in Onanimatorik.
If we're going to do IK, we'll first bind the IK position. The authorities that IK can control have given enum
Then we're going to set the weight weight, the range is 0~1, this is set to 1.
1Avatar. Setikpositionweight (Avatarikgoal.leftfoot,1.0f);2Avatar. Setikrotationweight (Avatarikgoal.leftfoot,1.0f);3Avatar. Setikpositionweight (Avatarikgoal.lefthand,1.0f);4Avatar. Setikrotationweight (Avatarikgoal.lefthand,1.0f);5Avatar. Setikpositionweight (Avatarikgoal.rightfoot,1.0f);6Avatar. Setikrotationweight (Avatarikgoal.rightfoot,1.0f);7Avatar. Setikpositionweight (Avatarikgoal.righthand,1.0f);8Avatar. Setikrotationweight (Avatarikgoal.righthand,1.0f);9Avatar. Setlookatweight (1.0f,0.3f,1.0f,0.5f);
If we set the weight of Leftfoot to 0, the following will happen
The bindings for IK in the official script are not in Onanimatorik, but in the update, and then there is the problem of binding failure.
So I put them all in the Onanimatorik. You can do it.
About IK operations ~, give less.
1 //set right-hand ik position2 Avatar. Setikposition (Avatarikgoal.righthand, righthandobj.position);3 //set right-handed IK rotation4 Avatar. Setikrotation (Avatarikgoal.righthand, righthandobj.rotation);5 //get the right-hand ik position6Righthandobj.position =Avatar. Getikposition (Avatarikgoal.righthand);7 //get right-handed IK rotation8Righthandobj.rotation = Avatar. Getikrotation (Avatarikgoal.righthand);
The full Code ~ (ikactive) does not open when the ball follows the person, open when people follow the ball.
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classMyik:monobehaviour {5 6 PublicTransform bodyobj =NULL;7 PublicTransform leftfootobj =NULL; 8 PublicTransform rightfootobj =NULL;9 PublicTransform lefthandobj =NULL;Ten PublicTransform righthandobj =NULL; One PublicTransform lookatobj =NULL; A PrivateAnimator Avatar; - Public BOOLIkactive =false; - the voidStart () - { -Avatar = getcomponent<animator>(); - } + - voidOnanimatorik (intLayerindex) + { A if(Avatar = =NULL)return; at - if(ikactive) - { -Avatar. Setikpositionweight (Avatarikgoal.leftfoot,0.0f); -Avatar. Setikrotationweight (Avatarikgoal.leftfoot,1.0f); -Avatar. Setikpositionweight (Avatarikgoal.lefthand,1.0f); inAvatar. Setikrotationweight (Avatarikgoal.lefthand,1.0f); -Avatar. Setikpositionweight (Avatarikgoal.rightfoot,1.0f); toAvatar. Setikrotationweight (Avatarikgoal.rightfoot,1.0f); +Avatar. Setikpositionweight (Avatarikgoal.righthand,1.0f); -Avatar. Setikrotationweight (Avatarikgoal.righthand,1.0f); theAvatar. Setlookatweight (1.0f,0.3f,1.0f,0.5f); * $ if(Bodyobj! =NULL)Panax Notoginseng { -Avatar.bodyposition =bodyobj.position; theAvatar.bodyrotation =bodyobj.rotation; + } A the if(Lefthandobj! =NULL) + { - Avatar. Setikposition (Avatarikgoal.lefthand, lefthandobj.position); $ Avatar. Setikrotation (Avatarikgoal.lefthand, lefthandobj.rotation); $ } - if(Rightfootobj! =NULL) - { the Avatar. Setikposition (Avatarikgoal.rightfoot, rightfootobj.position); - Avatar. Setikrotation (Avatarikgoal.rightfoot, rightfootobj.rotation);Wuyi } the if(Leftfootobj! =NULL) - { Wu Avatar. Setikposition (Avatarikgoal.leftfoot, leftfootobj.position); - Avatar. Setikrotation (Avatarikgoal.leftfoot, leftfootobj.rotation); About } $ if(Righthandobj! =NULL) - { - Avatar. Setikposition (Avatarikgoal.righthand, righthandobj.position); - Avatar. Setikrotation (Avatarikgoal.righthand, righthandobj.rotation); A } + the if(Lookatobj! =NULL) - Avatar. Setlookatposition (lookatobj.position); $ } the Else the { the if(Bodyobj! =NULL) the { -Bodyobj.position =avatar.bodyposition; inBodyobj.rotation =avatar.bodyrotation; the } the About if(Leftfootobj! =NULL) the { theLeftfootobj.position =Avatar. Getikposition (avatarikgoal.leftfoot); theLeftfootobj.rotation =Avatar. Getikrotation (avatarikgoal.leftfoot); + } - the if(Rightfootobj! =NULL)Bayi { theRightfootobj.position =Avatar. Getikposition (avatarikgoal.rightfoot); theRightfootobj.rotation =Avatar. Getikrotation (avatarikgoal.rightfoot); - } - the if(Lefthandobj! =NULL) the { theLefthandobj.position =Avatar. Getikposition (Avatarikgoal.lefthand); theLefthandobj.rotation =Avatar. Getikrotation (Avatarikgoal.lefthand); - } the the if(Righthandobj! =NULL) the {94Righthandobj.position =Avatar. Getikposition (Avatarikgoal.righthand); theRighthandobj.rotation =Avatar. Getikrotation (Avatarikgoal.righthand); the } the 98 if(Lookatobj! =NULL) About { -Lookatobj.position = avatar.bodyposition + avatar.bodyrotation *NewVector3 (0,0.5f,1);101 }102Avatar. Setikpositionweight (Avatarikgoal.leftfoot,0);103Avatar. Setikrotationweight (Avatarikgoal.leftfoot,0);104Avatar. Setikpositionweight (Avatarikgoal.lefthand,0); theAvatar. Setikrotationweight (Avatarikgoal.lefthand,0);106Avatar. Setikpositionweight (Avatarikgoal.rightfoot,0);107Avatar. Setikrotationweight (Avatarikgoal.rightfoot,0);108Avatar. Setikpositionweight (Avatarikgoal.righthand,0);109Avatar. Setikrotationweight (Avatarikgoal.righthand,0); theAvatar. Setlookatweight (0.0f);111 } the }113 the}
With an egg, ik fun ~ ~ hehe ~ o (* ̄▽ ̄*) ブ
Unity Animator Animation state machine in-depth understanding (ii) IK control