- Home /
The question is answered, right answer was accepted
Mecanim - Bone Target Matching = Whole object translation!
I'm trying to fangle my way through target matching with Mecanim. When I perform "attack" I wanted the Player hand to migrate towards the specified point "enemyHead". Everything is working at the required points except that instead of the hand moving it pulls the entire model, sliding across the floor until the hand is located close to the specified point.
Is this all I'm going to get out of it? I don't see a way to mask the rig for specific bones. Am I being too hopeful or am I missing something?
The ideal situation I was hoping to see is that the attack swing would happen as normal except the hand would go through the desired point. Of course, it seems this is far from the case.
I've set up a scene with a functioning Mecanim rigged character and another object which is simply an enemy model. In the following script for simplicity I drag the enemy "Head" bone object to the inspector field.
private var matchAnimator : Animator;
public var enemyHead : Transform;
function Start ()
{
matchAnimator = GetComponent(Animator);
}
function Update ()
{
if(matchAnimator)
{
if(matchAnimator.GetCurrentAnimatorStateInfo(1).IsName("attack"))
{
Debug.Log("Attacking!!");
matchAnimator.MatchTarget(enemyHead.position, enemyHead.rotation, AvatarTarget.RightHand,new MatchTargetWeightMask(Vector3(1.0,1.0,1.0), 0), 0.44, 0.55);
}
}
}
I'm starting to think no-one uses $$anonymous$$atchTarget as it doesn't do what it says on the tin...
Hmm, that seems closer to $$anonymous$$atchTarget than $$anonymous$$atchTarget itself :D Unfortunately, it's pro only so out of my bounds for the moment. I'm familiar with I$$anonymous$$ from the $$anonymous$$odeller but I never knew what functions existed in Unity for using it. Now that I see it, $$anonymous$$atchTarget looks like a very poor substitute.
The advantage of $$anonymous$$atchTarget was supposedly that you could use it during an animation. I was going to use it to hit heads and bounce off shields. Seems I can't do that :D
Back to the drawing board!
Thanks for the reply Loius. +1
I tried a custom I$$anonymous$$ script which was supposed to work on 2 bones and this seems to work in very much the same way, dragging my character around!
EDIT: Changed all the transforms in the script, now it seems to behave well. Added to Controller to enable/disable the I$$anonymous$$Control script between two points of an animation, so during an attack the hand is directed towards the specified object.
The I$$anonymous$$Control script came from a free I$$anonymous$$ package on Asset store. It's a bit glitchy but has all the basics in there for $$anonymous$$anual I$$anonymous$$. Bit of tweaking, it'll look good.
Answer by Loius · Apr 27, 2014 at 07:24 PM
I've never touched match target, but if it's like normal IK there should be a setting to change how many bones it affects - in your case you only want to affect the hand and the two arm bones I imagine.
Does this link help? http://docs.unity3d.com/Documentation/Manual/InverseKinematics.html
Converted yours to answer as it is what brought me to the conclusion : it's the intended behaviour of $$anonymous$$atchTarget, I$$anonymous$$ is the way to go, custom or built-in.