I have uploaded it to make it clear what my problem is
Dont know what happen to the textures =(
A,S,D,W is to move and K to draw guns. Now everything is working but when you draw guns, the position of the guns does not stay in the hands, it moves back and forth. I have tried to parent the guns to the hand but the guns appear behind the head. Anyone know how I can fix this?
You need to keep an offset for when the gun is in the hand, and when it is on the hip.
During your draw Coroutine, you need to swap the parenting from the hip to the hand, and make the localPosition match the offset and the rotation match the hand.
During the holster Coroutine, you would need to swap the parenting back to the hip, and make it’s localPosition match the offset for the hip and the rotation what it originally was. (you can store rotation as well)
These are timed events, so you will need to build those coroutines keeping in mind that (0.23 seconds) into the animation, parenting changes.
Don’t have any experience with that, but how do you get the guns in the hands in the first place? Maybe you could just “attach” the guns to the bones that are in the hands? And if you already do that… well, perhaps the bones or the object itself is lagging behind?
But I dont understand what you said because I know very little about programing. I have tried to parent the guns to the hands but the guns appear behind the head and I havent tried fixing the rotation yet. Rotation seems to be fine, i just want the guns to stay in one place when they are in the hands.
If its not too much trouble then can you please explain a little more or write a little script?
Its an animation which I made in blender where. The guns were parented to the thighs in blender and animated. They move with the hands when you play the animation.
i know what’s going on with your guns, this happened to me before. first of all what is the 3d app you are using to animate your character? because it’s not a scripting issue. i’m guessing blender anyways i use maya. but here it is what i’m trying to say.
when you animate your character i believe you used a rig for it anyhow it seems that you parented your weapons to the rig that controls the hands. so basically it’s a parenting issue. what i’m saying is for you to make shure you parent the guns to the bones when doing the animations. or you can fix it in unity too. but if the parenting in unity doesn’t work then use the 3d app because the actual pivot of the objects could be moved. so that’s why you should try fixing that in the program that you used to animate your character but first try it on unity.
Animate the parenting to the hand joint based on set key driven influences. This means the gun will only follow with the parented hand joint if the set influence is high enough, and not always follow the hand joint.
Edit:
Or what foxter said, you parented the gun incorrectly. You may of parented it to a control or something rather than the hand joint it’s self.
OK, so in Blender I parented the guns to the hands and made a drawing guns animation and imported it to Unity but im still getting the same results. With the new animation, the guns stay on the hips and dont move to the hands, I have tried adding a Mixing Transform but they still stay parented to the hips.
With the old animations I have tried the following script
if (GunsDrawn == false)
animation.CrossFade ("DrawGuns");
gameObject.Find ("gun1").transform.parent = gameObject.Find ("Bip001 L Hand").transform.parent;
else
if (GunsDrawn == true)
animation.CrossFade ("DrawGuns2");
gameObject.Find ("gun1").transform.parent = gameObject.Find ("Bip001 L Thigh").transform.parent;
If I take the “else” out, the gun is parented the hand but the rotation is not right and I cant get it back to the hips but if I put the else in I get an error saying “Expecting { found else”