[#03] Unity Animation Rigging - Attaching a weapon using two bone IK constraint
ฝัง
- เผยแพร่เมื่อ 25 ส.ค. 2024
- In this tutorial, I show you how to attach a weapon to your character, using Unitys Animation Rigging package and the two bone IK constraint with no coding.
►Next Video: • [#04] Unity Animation ...
►Previous Video: • [#02] THIRD PERSON SHO...
Assets and packages used in this video:
► Synty POLYGON - Starter Pack: assetstore.uni...
► Animation Rigging: docs.unity3d.c...
► Cinemachine: unity.com/unit...
** Share this video **
• [#03] Unity Animation ...
** Subscribe :) **
/ @thekiwicoder
Follow Me!
► / thekiwicoder
► / thekiwicoder
► / discord
This is such a godsend. Seriously, straight to the point, comprehensive and MOST importantly - doesn't start with "create a new unity project and build your entire game around only this one feature working". It's so helpful to have a tutorial that understands it's going to be used in the real world and fits in with other workflows. For instance, I saw a similar tutorial that required you to rebuild your entire character rig from scratch in blender and put you into a workflow where many animation features would then be impossible down the line. Great job!
Pro Tip: When you are setting up your 2 bone IK Constraint bones all you need do is populate the tip joint, then right click on the 2 bone ik components script header and select Auto Populate from Tip it also auto creates the IK_target and IK_hint game objects.
next pro tip - you can actually pose your character using the IK controls in edit mode if you have the Animation window open and click 'preview'. So no need to go back and forth between play mode and editor mode. In the animation editors 'Preview' mode you can also play the animations to see how they would look with the IK system. You'll notice that on the animation window if you press play in edit mode it will play the selected animation in Preview mode.
Thank you broo i love you
There is also one more Caveat I forgot to mention - If you have Use Root Motion selected on your character, then press the preview button or the play animation button, your character will snap to it's parents world position. I have a Player System object and under this I have the model, my Player System object was located at the world origin, but the character was not. When I was Root Motion in the animator controller, it would snap my model to that location - so if you're gonna use root motion, be sure to either turn it off when you are doing your IK adjustments, OR make sure that your animated model is at the same location as it's parent. You're welcome. 8)
And hey, Kiwi coder - excellent work brother.
For anyone struggling on getting the hands to snap to the weapon...You have to make sure that the RigLayer is IN the mesh your working with (SM_Character_Male_01 in this case) and that the "gun" object is ALSO a child object of the mesh. Wasn't too obvious to me and took a few hours to figure out. Looks something like this:
v SM_Character_Male_01
Character_Male_Face_01
> Root
> RigLayer
v Gun
ref_right_hand_grip
Later in the video, TheKiwiCoder also points out that you can put the gun within the root parent to follow transformations. This still works.
Thanks for the awesome video!
mine still aint working :(
Thanks
Thanks
F* Legend! Thanks
This is the finest tutorial on Animation rigging on Unity. You explained everything and very clearly. Subscribed!
def
You're an absolute god. Your videos are packed full of only useful information and no excessive pauses or explanations. And using all the latest tech from unity to boot (except the new input system but that's easy enough for me to refactor myself).
Thanks for the kind words :) Cinemachine & Animation rigging is a great combo. I'm yet to checkout the new input system or dots tho
I used the standard scripting method to do this, but this still helped me understand how IK works and told me about the existence of hints when the Unity docs did not so thank you!
Awesome! There’s another built in Ik system too you can use as an alternative to this.
Great tutorial. What I really appreciated about it was the fact that it wasn't just add the weapon to the hands through IK. That would have been good enough I guess, but you went to trouble shoot the issues of it not looking right and then how to address these issues. Thanks a mil.
Thanks! You saved me hours with "Rig Transform" on the gun
Is only needed if the gun is a child of a character
@@dftpunk Thank you so much I don't know why but if I put a rig transform on my gun I cannot change any of the guns transform values which is exactly why I need it to aim the gun up and down. I spent at least an hour trying to solve this and saw your comment and just unchilded the gun. Didn't fix the rig transform not working but it gave me a work around.
I'm new to animations in Unity and really want NPCs to carry weapons. This tutorial is excellent. Thanks so much. Subbed!
Muchas gracias
Awesome video - perfect for what I was doing, and I never would have thought I'd needed the animation rigging package if I hadn't found this - thanks!
Great to hear!
This is like the fourth time I'm seeing this video, I've finally understood and now I can do this without watching again and again. Thanks a lot.
Hoping you'll be active again.
Outstanding tutorial - thank you so much. My character is a Mixamo model so rig structure different but I still got it to work.
Thank you! Awesome it worked for you :)
Hey, what adjustments did you have to make to get the Mixamo model to work? Thanks
I also have a Mixamo model but how did you make it work?
@Shamshad Jaweed ya, same here, but do you got a fix, because we can't always use the polygon pack ¯\_(ツ)_/¯
@Shamshad Jaweed how bro?🙏🤔 wait I think, that my gun pivot is making some weird movements, don't you think it will affect the character?
Cool, thanks! Hello to Russia too :) Your guides are the best, keep up the good work))
The best thing since peanut butter my guy. You just saved me a ton of time!!!
Kia ora! best Animation Rigging tutorial so far... Good work!
I still watching your other videos, I'm looking for the best practice to apply animation using the Animation Rigging.
The use case I'm trying to reproduce is draw\save\aim the guns and blend those animations with the idle/walk/run animations..
Well, for me at least, it works better if you place the gun inside the spine (chest of your character rig). Therefore, the gun can rotate in the same way as the characters' rotation.
Thanks for the video! I managed accomplish this behavior for my character just yesterday but your solution seems a lot more straightforward.
No probs! I’m interested, what was your solution?
@@TheKiwiCoder I had references under Rig hierarchy for both the handle (meant for R_hand ) and the barrel (meant for L_hand ) of the gun. Then I used m_parent constraint to hook the handle to stick with the right hand ik. But then I ran into a problem because the same trick wouldn't work for the left hand and the same time. So I hooked the left hand to stick with the ref_barrel by using again multi_parent. So in the end the constraint hierarchy was something like this from the top: right_hand_ik => gun regerences => left_hand_ik where r hand ik naturally controlled the movement. And well it worked but I still had some trouble with the gun's orientation :D
Lightkitara Interesting idea to use the right hand to control the gun! I made the hand IK references children of the weapon to make switching weapons a bit easier.. that was the idea anyway. Whenever I get orientation issues I double check the ‘Maintain offset’ parameters on the constraint. The position and rotation constraints can be used in place of the parent constraint, giving you separate control over each. They let you specify offsets too.
Thank you for this, it helped me so much in understanding unity rigging!
you sir, saved my sanity
this channel is gold
Fantastic video and very clear directions. Thanks for making it easy!
Thank you so much, so much info in such a short time.
The video I was looking for. Thank you so much.
This is a great tutorial and highly underrated channel. Thank you!
Thank you so much! Helped out a lot!)
very fun, can't wait for more
Hey there Kiwi, do you know if this system was ever updated to support the ability to change the source object with code? You see I have a character that is constantly changing weapons, and therefore needs to be able to change the source points when those weapons are changed. I am seemingly unable to reference the source object via script even when using UnityEngine.Animation.Rigging;
Think you could point me in the right direction? Great video! Cheers.
Hi you can reference the source objects via constraint.data.sourceObjects. It's also possible to add multiple source objects to the constraint and toggle the weights of each on/off via script or animation. Hope that helps
I have witnessed two legends talking to each other O^O
@@firebolttz9058 lol
Superb they've really kept going with Unity. Getting closer to not needing code although I still think code helps tie things together a lot better. Still possible to make great stuff without it though. First time really using Unity a lot since 5. Working on a game, it's a pretty big project but trying to keep it humble in every way that will still go over smoothly.
Excellent job!! You got a new subscriber!
Thank you!
Learned alot with this video! Thank you!
Great, I need more tutorial about animation rigging
Checkout my follow up video to this one! th-cam.com/video/ajmp3J7N3Ow/w-d-xo.html
wonderful tutorial. works fine for me.
love u man this is what i needed
for those of You guys, who struggls with floating character, just make sure that none of your bones is somehow scaled. in blender or whatever editor You use, apply all transforms (scale, rotation) to your character before export FBX, and may god be with You
I did. It's still floating....
Hey! I'm new in Unity and I have same problem. I imported my character from assets store, what to you mean by making sure that none of bones are scaled?
@@yeetbox5843 just check few random bones transform for being scaled for example 0.99999 on some axis. Or sometimes bones could be ok, but mesh is scaled 100
Great tutorial. Very useful. Thanks!
Thank you man, awesome tuto!!
how to fix the aiming pose, the left hand wont reach the grip?
can you make a tutorial like this for fps games
working like a charm! Thanks
Tutorial on TPS Controller for mobile Please...
thx so much my friend!
How would this work for switching animation states, like from having a pistol equiped and switch to a rifle. would you have to create multiple ik nodes for each weapon type within the player prefab? and im guessing setting each node weight in code...
Remember that animation states can also animate the properties of the rig, such as weights. It would be a mix of this and scripts to swap out the weapon and control targets. The easiest method I’ve found for authoring is defining the ik targets in the weapon prefab.
@@TheKiwiCoder Hi, yeah i was thinking of the same method, reference the ik nodes in each weapon prefabs script.
Im currently making a GTA style game, but so far havent even started the weapon systems. Just been looking around to try and solve issues before i get to them, so far ive got most of the systems coded: Player movement, day and night cycle with time, health and armor, wanted level system (for player and peds) police units up to the army, EMS coded also, all the UI inc minimap and a world map, money system inc ATMs & currenty using the city demo scene to develop it all on.
Ive been trying this project for a few years now, using the synty packs, the last project ran into big issues that i couldn't easily solve. I had more systems done for that project, like vehicles with real physics and weapons (minus any ik), so i can reuse some code from there.
Thanks for getting back, most don't and that's not helpful.
@@TheKiwiCoder ok but how
@@cooldev2203 keep following the series, or jump ahead. Theres videos later on that cover weapon switching.
Thank you
Best lesson.
Good luck!
Videos are great. Would be awesome if they where more of a continuous series other than some what separate videos. Still they are awesome.
What if i just want the weapon to follow the positions of my hand, so that when my already made idle, walking, running and aiming animations have the weapon fit into the hands during those animations?
Best video till now, everything explained with so simplicity 🔥🔥🔥❤️
Really,Great work bro
Nice tutorial...awesome 🔥
Wow That Was really Cool
Is exciting how technology evolves.
I was wondering If Someday we tell to unity "grab that shit", "i want to move the character at 5 km/h" and he does. Lol. Would be fun. And we can spend more time worryng about telling a nice story instead of configuring weird shit.
Yeah.. unity is sorely missing a decent third person template like unreal has.
Great, it is a good Show!!!
Yes it was!
Great Content!
Thank you very much!!!
2:00 setup base ik rig 3:00 setup hand position reference at object like "hand handler" | replace reference with target in ik 5:10 add rig transform to "hand handler"
Great video, thanks ☺
wow thanks! helps soo much
This is a huge help, thanks man!
cool.
very nice video! subbed
thanks for sharing
This was great, keep it up the good work!
can you do a tutorial on how to make the arms unaffected by the rotation of it's parent please?
This is probably pretty cool for realistic games, but I think its probably just overkill for arcade style games. I think I'll stick to one parent with pre-baked animations. The other thing is, if your characters are very stubby toons, they might not be able to hold a gun with two hands.
nice one
Thanks !!🙌
AMAZING
Yes
please make a tutorial on weapon scoping
Take my like. I have been trying to figure out why my IK was not moving with my gun and it was this video that introduced me to the Rig Transform component. Thank you.
Edit: Actually the left hand does not stick to the gun when it is moved by other constraints on the rig. The hand position is on another Rig just below the aiming rig. Do constraints only take into account other constraints on the same rig?
Edit edit: I was able to workaround this issue. I originally had:
Aim Rig (Only on when aiming)
Aim Constrain
Aim Constrain
Left Hand Rig (Always on)
IK Constraint
The workaround is:
Left Hand Rig (Always on)
Aim Rig (Only on when aiming)
Aim Constraint
Aim Constraint
IK constraint
The IK now properly calculates the position to the left hand placement. Tho with a bit of a lag oddly(not sure what's up with that). Constrain order is very important!
hello, i need help, please! I have a list character for character selection, so now. How can i attaching weapon for them?
This top notch.
I am having issues with the ref_right_hand_grip. It only works when I bring it past the ground instead of on the gun like your video, any tips? Thanks
trying to use a different character with mixamo animation but the hand rotation is not working. Anyone have any ideas how to fix it?
Video is perfect, a bit slower on the clicks would be appreciated:) Had to watch it in reduced speed haha
I cant get the two bone IK constraint to work. I added my rig layer and everything, and ive set my source to be the gun, but when I press play, my player mesh snaps to a far away position, and then starts floating in random directions. What is even more odd, is that my gun, which is a child of my character mesh, stays where it is meant to be (since it is a child of the character mesh, which is the child of the empty parent which contains player movement), but the character mesh does not. I'm not exactly sure what is causing this, could it be that I set my player movement on an empty, then had my mesh with my animator as a child to it? If anyone knows how to solve this, I would greatly appreciate help.
I had a similar issue and found my answer at answers.unity.com/questions/1745150/why-does-animation-rigging-send-my-rigged-characte.html . The issue had to do with the scale of my character's root bone
Thx for tutorial, you help me a lot
I'm following the tutorial but I have a problem with Rig Transform, doesn't work on play mode (doesn't update the position when is attached to the weapon, but if I move the position of the gun and press the play mode, the rig transform is updated...) I don't know what is happening, any solutions?
I know this is from a few months ago but I had this problem too. I updated to unity 2020.3 LTS then things worked like in this video
@@davidson2727what thanks, I will try now
Can u make a quick tut about aiming and shooting? ..this vid helped me a lot. Tnx man!
Hey! This video shows how to aim a weapon: th-cam.com/video/ajmp3J7N3Ow/w-d-xo.html
Shooting tutorial coming soon!
Great tutorial. I am using the same assets but the hands don't stay attached to the IK reference points, they only loosely follow them and it's impossible to place them correctly. The two bones are set correctly. I noticed that the prefab is scaled 0.01. It seems to work in a different model which is not scaled. Could that be the problem?
EDIT: this happens with the prefabs in the prototype pack, it works fine with the characters in the starter pack.
Awesome stuff!! This is has saved my sanity!!
Hi my player automatically changes his position on play. It starts to float in the air but the weapon stays on ground .Any solution ?
How would you go about guns that have for exampe grip attachments where the left hand need to switch between different locations and poses?
Great tutorial,but here I have an issue,which is when I attached Rig Builder to the character and hit play,the model gets stuck into the ground.Does anyone know how to solve it?
Thx!
big thanks for you !!
small question
If I have different guns the fingers are arranged differently.
Should I do animation for each rifle individually or is there a way to do it in Unity?
A different animation for each weapon is likely easiest.
subscribed!
I thought there are mosquitos around me lol.
Thank you sooo much, I subbed, this tutorial was so damn useful and you explained everything sooo good, thank you very very much again
the best
I created my own character using blender and exported it correctly, character doing perfectly animation with Locomotion and Aiming script, but when i attach rig builder and IK stuff and hit play he wents away from camera and starts floating in air, when i do it with Polygon starter pack character its doing correctly everything, bt not with my own character.,.. plz help
Not sure if this helps, but my character was floating away as well and I was able to fix it by unchecking the "Apply Root Motion" box under the Animator component.
Here's a comment I found from someone who had the same problem:
for those of You guys, who struggls with floating character, just make sure that none of your bones is somehow scaled. in blender or whatever editor You use, apply all transforms (scale, rotation) to your character before export FBX, and may god be with You
I hope this helps, also credit to the guy who made this comment first.
Thank you for this great video! But I have one question during the procedural, that I'm using a custom character and with its avatar, there is no left nor right clavicle in the list, so when I'm trying to attach the gun under the player's avatar, right arm or right shoulder, the arm and hand just twists and I'm unable to fix it. So what should I do if I don't have clavicle?
PS: I got the rig from mixamo.
It’s not detailed in this video, but you could use a multi parent constraint and attach to the spine or hips, with an offset.
@@TheKiwiCoder Thank you! I also have another question, which what do i need to write in script in order to disable the Rig Builder component during the game is running?
WJS Jason setting the weight to 0 should disable everything
So glad someone else had the same issue as I did, multi parent constrain on the spine, and I set the weapon as the constrained object, works like a charm!!
When I initially setup my character I added some animation clips from mixamo and attached the gun as a child of the character's hand. This kept the gun in place during my character's running animation.
Does anyone have suggestions for how to maintain this behavior, but then switch to IK (as shown in this video) when aiming?
My latest video will release today which covers this!!
@Nagato is better than Punk Naruto any reason to use ik? Might be easier to use animation and keyframe the hands to the correct locations throughout the clip
Me tweaking hand positions for 20 mins 😊
Me leaving play mode 😊
Me leaving play mode 💀
Did you make it back to play mode? 🤞
Awesome x3
im stuck in t pose.........hands cant attach to the gun .......im using mixamo swat model
Make More Videos Please! Great Quality Content
sir i cant rotate and change position when in game mode of the bones
Can i set the hand position by code?
Yes, add a public transform field to your script, and assign the left/right grip node to it. Then you can modify it in code.
I cant change position of hand during game play mode. its locked help me please.
there is another thing, your character will only use 1 weapon, it is kinda not possible to switch weapons...... is there a way to round around that?
It’s a bit of a process but yes it is possible. The basic idea is not to reference the weapon directly from the constraints.
@@TheKiwiCoder yup, make an empty object that act as weapon container, and IK objects that is fixed for the character itself, whenever you change the weapon, a script will simply change the position and rotation of those IK points, based on which type of weapon
you offer us a tutorial for topdown shooter game ?? And thank you for this tutorial
Great idea. Thank for the suggestion!
@@TheKiwiCoder thank you 😊
What if i want to equip another weapon? How can i change the rig in runtime so it adapts to the new weapon?
He's shown it in his different video