this process is pretty simple. I tried a method where I took three points - root bone pos, pole, and target pos, and had each bone rotate to a point on the curve, using boneIndex+1/boneCount. It worked, but with overshoot, then I tried inverse kinematics, but could not make it work. Your video helped solve my problem, thank you for the video.
This was a really great tutorial! Thank you very much! This is a complex subject, but I thought you did a great job of explaining it, and your code is very easy to read.
Started out a little sceptical because of how little I understood the gizmo code, but you actually did a really great job of explaining the algorithm! Awesome work!
Well i think am gonna have a hard time trying to implement it in my own way and my own code , this tutorial really helped me to understand IK ...thanks !!!
man no matter what i do i can not get this to work at all. my mesh will not move at all even with the correct ik edit: didnt realise you had to press play
@@sigorharaldsson4067 Careful though, I only use it after I know everything works, and you have to handle special cases like runtime parenting for ex bool safeToParent = true; if(Application.isEditor && !Application.isPlaying) safeToParent = false; pistonExtensionTransform = transform.parent.Find("Piston Extension"); if (parentMe && safeToParent) { Transform jointTransform = transform.parent.Find("Joint"); if (jointTransform) jointTransform.parent = parentMe; Transform jointATransform = transform.parent.Find("Joint_a"); if (jointATransform) jointATransform.parent = parentMe;
if (pistonExtensionTransform) pistonExtensionTransform.parent = parentMe; transform.parent = parentMe; }
Thanks alot man! It really helped me to solve my rotation Issue. I did a few things different because I dont calculate the Plane rotation stuff because I only correct ground alighnment with it.so I could assume alot of calculations and save a few things.
Thank you for the very useful tutorial. One thing I might add. I'd suggest calling the Init() method from Start rather than Awake(); Otherwise, you can get strange behavior if you try to change the Target at runtime even if the script is disabled in the editor before you hit play.
@@anonymoussloth6687 Sure, In Unity all components have a start and awake function. Awak always gets called first for all components in the scence, then start gets called for every component in the scence. Moving his Init() method to the start function vs the awake function will allow you to change the IK target while the game is playing. Otherwise if you leave Init() inside of awake it will cause problems. However, If you don't plan on changing the IK target while playing the game you won't have any issues.Hope that helps.
â@@fookustudios3279 Thanks! But I am still confused why a dynamic IK target will be an issue if it is in awake. As I understand, awake is called for all components when the scene is loaded. Then start is called one by one for each component. right? And this leads me to another question: if both awake and start are called in the beginning (with awake being first) arent they basically the same? First all awake functions are called for all objects, then all start functions are called for all objects right?
â@@anonymoussloth6687 Start and Awake are the same in the sense that they will both get called before the object "comes to life" in a scene. However because all Awake methods get called first, then all start method get called next, developers typically use the Awake method to iniaitalize all variables local to the component itself, then use the start method to setup references to other objects within the scene if needed. For example. Component A has a variable that references another object in your scene(Object B). It that case you'd want to setup that reference in the start method, because if you used the awake, that variable you created may not be able to create the reference to the other object B because Object B hasn't called it's Awake function yet. So instead you'd have component A establish the reference to Object B in its Start method. That way you know that Object B has fully initialized because it's Awake method is garunteed to have been called that this point. I'd suggest doing some experiments. First , use the code as is, and change the IK target while the game is running, although I haven't looked at it recently, if memory serves, it will throw an exception or cause strange behavior. Then comment out that Init() in the awake, and add it to Start(). Compile, change the IK target at runtime and see what happens. If you can step through the code as it executes and you can watch everything in action. Still confused, just respond. Cheers.
I have created a bone rig, and I am almost done an entire animation system, the last thing I need, is to do inverse kinematics. I am working on a program called World Seed. It is a bone rig, that is threaded. The entire animaton system I created is threaded. this is the last step in my process.
Nice tutorial! I used to do IK in 2D by using rotations in a similar way, but using positions is way easier it seems. However, is there an easy way to limit rotations? I have some ideas but that would require a lot more maths in the forward and backward iterations.
Hello, I am trying to create similar inverse kinematik, my question is what kind of joints exist between 2 links or what seems to be called bone in blender. beacause in my interface whenn i go for creating a spherical joint it seems to lock the translational movement which the itterations talks about when the last child link moves away from link, or have i completely misunderstood?
10:06 instead of using an if statement to check if you are in the first bone you should do the first bone before the loop to have NOT an redundant if statement, as if statements are one of the most taxing statements on the CPU.
How can I have a weight parameter so that I can control the influence of IK ? Say if it is 0, then the normal animation will play, while if it is 1 then the IK will override the animations. I tried to create a lerp when setting the position and rotation to the actual bones via a public weight variable to control the influence of the IK. But dunno why it doesn't work. I have checked the entire code and I can see that only two functions are responsible for setting the position and rotation so I directly added the lerp there. But it doesn't seem to work and instead gives a weird shape. Though if I just change the weight from 1 to 0 and vice versa directly then all works fine. I am not sure what I am doing wrong. Additionally, Fabrik algorithm itself isn't hard, but the actual hard thing to understand is how to rotate the mesh with respect to the calculated positions. I see there's a heavy math going on when trying to set position and rotation of the bones. And perhaps it's there that I am missing out something. Stuff like multiplying quaternion with a vector then assigning that to a vector3 makes no sense to me how that happens lol. I guess this is a great opportunity for me to revisit and learn more about trignometry, linear algebra etc. I think the ability to control weight can be a great addition to your asset. Also I must say that the asset is very well made and the fact that you showed and explained us how you did all this is just fantastic. I liked the way you optimized your code and those crazy calculations with rotations are well thought of. Because the mesh translates perfectly with the IK target, which I was finding really really hard to do myself earlier. A great video and a great tool you made. Helps a lot for generic rigs :D
Okay, so in Blender I've scaled the cube as you did, then did the loop cuts as you did, then added the single bone armature as you did, then extruded the bones from that bone as you did, then exported to Unity as you did. But in Unity, the cube mesh does not move with the rotations of the bones? What might i be missing from your steps?
Nervermind. For some reason, after extruding the bones, i had to first switch to object mode, then select both the cube and then the armature, then press Ctrl+P and select 'Deform Armature with automatic weights'.
6:33 the distance between current and current.parent is the same as the distance between current.parent and current. What you sshould have done is new Vector3(scale,scale*10,scale) which would again safe on performance.
I learned so much from watching your excellent video and explanations, that I need to ask, after looking at your github repository... could I some how adapt your simpleIK framework for use in an Arduino robotics project? And if so, any feedback on how I can pull that off would be greatly appreciated, please & thank you!
hi, i have a question. is it intended that the script very slightly moves the leg even when the target is not moving? i have this weird behavior where the legs move by 0.0001 every frame almost randomly and it causes problems when trying to get the average leg y position. can you help me out?
btw. I just are done for the today and must leave, I will critize your code furhter down the line. So far all my improvments worked just fine. But I still like your tutorial, pretty quick and clear stuff.
good info, but only have one gripe. Using 'var' all over your code and not using explicit declarations leave your code unreadable. Mainly a style choice, but it helps to have explicit variable declarations when you go back to your code later.
var is something that comes with experience. Very rarely can you not tell what a variable is by its declaration. Also it makes it MORE readable IMO, not less. Take a dictionary for example: Dictionary myDic = new Dictionary(); vs var myDic = new Dictionary();
just found an issue where when i play an animation with it attached to the object with the animator or its children the bones shift and eventually the mesh of the arm deforms :\
5:48 the first one can't be null because so you don't need to check it and if the parrent is null than the current won't become the parrent so the current can never become null. Your check is redundant. Or am I missing something?
Thank you ! It was very helpful ! I recoded it from scratch, by listening to your instructions and explaination without copy paste your code. It was hard but it was doable. But the rotation part was too complicated to understand :< I wish to add some constraint to each bones to make some elbow or etc... Thank you !
Good tutorial, very cool. I have one problem, though. Somehow, even after writing all the code from scratch, the joints don't rotate at all, meaning that any parented limbs just stay in their normal rotation. Any help fixing this?
Oh wow. Inverse kinematics doesn't seem so intimidating anymore. It's pretty much just calculating the normal between the target position of the end effectors and the joint that you want to move, and maintaining the distance of the joints.
@@kurtisgibson2929 Hi Kurtis i have spent hours trying to recreate that ik actin on my sword but cant get it to work any ideas ? Hugo czcams.com/video/3ViP0cwIyPE/video.html
where the influence come at play i dont want the influence to be always at 1 but im dumb so i dont understand where to use to smothly go to the ik target
@@daanvanleeuwen8435 i solved by using a linear interpolation (vector3.lerp) between the actual transform of the foot and the target position of the ik with a variabile that increase or decrease following a curve in the animation. so with the foot is up its at zero when the foot goes down it increase to assigning the target position. it works not perfect but it works
Every time someone does something in blender, they fly around and I'm completely lost. I have to pause every couple seconds, research how he did each step Powerful tool, but very unintuitive
Yo man awesome job, btw i was able to twick alil bit the code, and made it run at least for now (without a pole) 4 times as fast. hmm like per 10k runs, the code dropped from 300ms, to about 80 ms , with 4 chain length.
Awesome tutorial, this is really good stuff!
so you are making advanced 3d games now?
and now it's in your new vid! nice
Came here after your video. I hope I will be able to apply this to my project.
so THIS is how you made the robot. AHAGH! Now I understand.
hold up only 7 replys to a dani comment (also i got no milk rn D: )
Basically kinematics... *BUT INVERSE*
-Dani 2020
Go away.
@@animationspace8550 wasteman
Thank you for this tutorial. I was able to apply this with my active ragdoll.
Thanks a Lot....Made my day after I was trying to figure it out for a month.....or even more
It is one of the greatest unity tutorials, thanks.
This is very complicated but you explained it so well I feel like I actually understand, thank you!
this process is pretty simple. I tried a method where I took three points - root bone pos, pole, and target pos, and had each bone rotate to a point on the curve, using boneIndex+1/boneCount. It worked, but with overshoot, then I tried inverse kinematics, but could not make it work. Your video helped solve my problem, thank you for the video.
Thanks ! Really simple to understand, it helps me to understand more things about Quaternions so now i can do IK and a lot of other things
Absolutely gorgeous! We need more tutorials like this :)
thanks a ton! CouldnÂŽt really wrap my head around IK.
This was a really great tutorial! Thank you very much!
This is a complex subject, but I thought you did a great job of explaining it, and your code is very easy to read.
Started out a little sceptical because of how little I understood the gizmo code, but you actually did a really great job of explaining the algorithm! Awesome work!
Dude it's just perfect. You've explained such hard task (for me it's hard) in such a simple way. I've understood everything.
Well i think am gonna have a hard time trying to implement it in my own way and my own code , this tutorial really helped me to understand IK ...thanks !!!
Danke fĂŒrs Zeigen!! Super Tutorial :) Weiter so!
How nice that the plane class exists.
man no matter what i do i can not get this to work at all. my mesh will not move at all even with the correct ik edit: didnt realise you had to press play
sorry but that is one of the funniest edits I've ever seen haha
@@sigorharaldsson4067 +1, loled so hard
You can actually make this script run in edit mode by adding the following attribute *before* declaring your class: [ExecuteInEditMode]
@@supernectar5022 that's actually pretty cool, will use that sometime
@@sigorharaldsson4067 Careful though, I only use it after I know everything works, and you have to handle special cases like runtime parenting for ex
bool safeToParent = true;
if(Application.isEditor && !Application.isPlaying) safeToParent = false;
pistonExtensionTransform = transform.parent.Find("Piston Extension");
if (parentMe && safeToParent)
{
Transform jointTransform = transform.parent.Find("Joint");
if (jointTransform) jointTransform.parent = parentMe;
Transform jointATransform = transform.parent.Find("Joint_a");
if (jointATransform) jointATransform.parent = parentMe;
if (pistonExtensionTransform) pistonExtensionTransform.parent = parentMe;
transform.parent = parentMe;
}
took about an hr and a half to finish but worth it :)
Thanks alot man! It really helped me to solve my rotation Issue. I did a few things different because I dont calculate the Plane rotation stuff because I only correct ground alighnment with it.so I could assume alot of calculations and save a few things.
Excellent tutorial with easy to follow explanation. I learned a lot and will definitely put it to use!
And excuse my manners... thank you very much for sharing :)
i wish i could like this tutorial more than once , thank you sir for this amazing tutorial
Thank you for the very useful tutorial. One thing I might add.
I'd suggest calling the Init() method from Start rather than Awake();
Otherwise, you can get strange behavior if you try to change the Target at runtime even if the script is disabled in the editor before you hit play.
I am new to unity so could you explain why this is the case?
@@anonymoussloth6687 Sure, In Unity all components have a start and awake function. Awak always gets called first for all components in the scence, then start gets called for every component in the scence. Moving his Init() method to the start function vs the awake function will allow you to change the IK target while the game is playing. Otherwise if you leave Init() inside of awake it will cause problems. However, If you don't plan on changing the IK target while playing the game you won't have any issues.Hope that helps.
â@@fookustudios3279 Thanks! But I am still confused why a dynamic IK target will be an issue if it is in awake. As I understand, awake is called for all components when the scene is loaded. Then start is called one by one for each component. right? And this leads me to another question: if both awake and start are called in the beginning (with awake being first) arent they basically the same? First all awake functions are called for all objects, then all start functions are called for all objects right?
â@@anonymoussloth6687 Start and Awake are the same in the sense that they will both get called before the object "comes to life" in a scene. However because all Awake methods get called first, then all start method get called next, developers typically use the Awake method to iniaitalize all variables local to the component itself, then use the start method to setup references to other objects within the scene if needed. For example. Component A has a variable that references another object in your scene(Object B). It that case you'd want to setup that reference in the start method, because if you used the awake, that variable you created may not be able to create the reference to the other object B because Object B hasn't called it's Awake function yet. So instead you'd have component A establish the reference to Object B in its Start method. That way you know that Object B has fully initialized because it's Awake method is garunteed to have been called that this point. I'd suggest doing some experiments. First , use the code as is, and change the IK target while the game is running, although I haven't looked at it recently, if memory serves, it will throw an exception or cause strange behavior. Then comment out that Init() in the awake, and add it to Start(). Compile, change the IK target at runtime and see what happens. If you can step through the code as it executes and you can watch everything in action. Still confused, just respond. Cheers.
@@fookustudios3279 Thanks so much for your detailed reply! I will try it out like you suggested
I have created a bone rig, and I am almost done an entire animation system, the last thing I need, is to do inverse kinematics. I am working on a program called World Seed. It is a bone rig, that is threaded. The entire animaton system I created is threaded. this is the last step in my process.
19:45 "Es Gibt" ich wuĂte ich kenne diesen Akzent.^^ Da haste ja geil gedanglished, aber ich denke die meisten checken das schon.
Er sagt aber "I skipped the index 0" und nicht "Es gibt the index 0", passt auch eher zum Kontext^^
thank you! it was a very informative and great tutorial.
Thanks man this is a great tutorial!
Nice tutorial! I used to do IK in 2D by using rotations in a similar way, but using positions is way easier it seems. However, is there an easy way to limit rotations? I have some ideas but that would require a lot more maths in the forward and backward iterations.
10 out of 10 would watch again!
Hello, I am trying to create similar inverse kinematik, my question is what kind of joints exist between 2 links or what seems to be called bone in blender. beacause in my interface whenn i go for creating a spherical joint it seems to lock the translational movement which the itterations talks about when the last child link moves away from link, or have i completely misunderstood?
10:06 instead of using an if statement to check if you are in the first bone you should do the first bone before the loop to have NOT an redundant if statement, as if statements are one of the most taxing statements on the CPU.
Thanks so much for this, it's such fun to be able to pet things
amazing video!
Amazing tutorial, thanks so much
Greeting my tschörmÀn companion. Nice vid!
Wow the Fast IK is free! Good tutorial.
That looks really awesome..
How can I have a weight parameter so that I can control the influence of IK ? Say if it is 0, then the normal animation will play, while if it is 1 then the IK will override the animations. I tried to create a lerp when setting the position and rotation to the actual bones via a public weight variable to control the influence of the IK. But dunno why it doesn't work. I have checked the entire code and I can see that only two functions are responsible for setting the position and rotation so I directly added the lerp there. But it doesn't seem to work and instead gives a weird shape. Though if I just change the weight from 1 to 0 and vice versa directly then all works fine. I am not sure what I am doing wrong.
Additionally, Fabrik algorithm itself isn't hard, but the actual hard thing to understand is how to rotate the mesh with respect to the calculated positions. I see there's a heavy math going on when trying to set position and rotation of the bones. And perhaps it's there that I am missing out something. Stuff like multiplying quaternion with a vector then assigning that to a vector3 makes no sense to me how that happens lol. I guess this is a great opportunity for me to revisit and learn more about trignometry, linear algebra etc.
I think the ability to control weight can be a great addition to your asset. Also I must say that the asset is very well made and the fact that you showed and explained us how you did all this is just fantastic. I liked the way you optimized your code and those crazy calculations with rotations are well thought of. Because the mesh translates perfectly with the IK target, which I was finding really really hard to do myself earlier. A great video and a great tool you made. Helps a lot for generic rigs :D
Okay, so in Blender I've scaled the cube as you did, then did the loop cuts as you did, then added the single bone armature as you did, then extruded the bones from that bone as you did, then exported to Unity as you did. But in Unity, the cube mesh does not move with the rotations of the bones? What might i be missing from your steps?
Nervermind. For some reason, after extruding the bones, i had to first switch to object mode, then select both the cube and then the armature, then press Ctrl+P and select 'Deform Armature with automatic weights'.
This is exactly what I need
Dam, very good tutorial man
the amount of ads in this video is getting to a point where it is very annoying,
yet helpful vid
6:33 the distance between current and current.parent is the same as the distance between current.parent and current. What you sshould have done is new Vector3(scale,scale*10,scale) which would again safe on performance.
se nota que sabes mucho, me puedes enseñar?
Great tutorial, thank you.
Wow. Thank you soooo, all much!
You are a life saver 100%
I learned so much from watching your excellent video and explanations, that I need to ask, after looking at your github repository... could I some how adapt your simpleIK framework for use in an Arduino robotics project? And if so, any feedback on how I can pull that off would be greatly appreciated, please & thank you!
hi, i have a question. is it intended that the script very slightly moves the leg even when the target is not moving? i have this weird behavior where the legs move by 0.0001 every frame almost randomly and it causes problems when trying to get the average leg y position. can you help me out?
Mensch, das ist toll!
Sir i am confused. If you are making a target? Then how will I make my player feet bend when o. Slope stair or anything that is not flat
Thanks great work! One question, why do you work in Root space instead of world space? is it to make some math calculations easier?
THANK YOU MAY GUY!!!
I can't get the cube to rotate with the bones in unity
Made a Spider with the help of this video :)
12:10 cool thing explaining why sqrMagnitude.
btw. I just are done for the today and must leave, I will critize your code furhter down the line. So far all my improvments worked just fine. But I still like your tutorial, pretty quick and clear stuff.
Is there a way to have the chains/bones rotate so that the mesh also rotates with it?
if you assign the bones to the mesh in a modelling software such as blender, when you import it back into unity it should work
Hey thanks for the nice tutorial!
I want to setup my chain so that the Bones are connected via Hinge Joints. How would you addvice to approach this?
you could use parent constraint compoinents
Thanks!
good info, but only have one gripe. Using 'var' all over your code and not using explicit declarations leave your code unreadable. Mainly a style choice, but it helps to have explicit variable declarations when you go back to your code later.
I was thinking that with `for (var i = 0;`
var is something that comes with experience. Very rarely can you not tell what a variable is by its declaration. Also it makes it MORE readable IMO, not less. Take a dictionary for example:
Dictionary myDic = new Dictionary();
vs
var myDic = new Dictionary();
Thank You very much sir
4 sure it is gold. Thanks.
This is exactly what i ve beenlooking for but i wonder how would you make the bones stretch within boundaries?
just found an issue where when i play an animation with it attached to the object with the animator or its children the bones shift and eventually the mesh of the arm deforms :\
turns out it wasnt ur code it was mine so i just ended up using urs ;-;
@@hoax5347 I'm having the same issue. Do you mind sharing what was the problem with the code?
@@SSleepyMorning i dont actually know, i just ended up downloading the persons code from somewhere
5:48 the first one can't be null because so you don't need to check it and if the parrent is null than the current won't become the parrent so the current can never become null. Your check is redundant. Or am I missing something?
Thank you ! It was very helpful ! I recoded it from scratch, by listening to your instructions and explaination without copy paste your code. It was hard but it was doable.
But the rotation part was too complicated to understand :<
I wish to add some constraint to each bones to make some elbow or etc...
Thank you !
how did u cut it in blender also how did u duplicate the bone without duplicating the armature
"I was looking for copper but I found gold"
i cant add amature i mean i can add it but not single bone
Good tutorial, very cool.
I have one problem, though. Somehow, even after writing all the code from scratch, the joints don't rotate at all, meaning that any parented limbs just stay in their normal rotation. Any help fixing this?
Nice! Would you create a timeline type of thing for runtime use? We can have an animation software!!! đđđ
Wait. Your forward axis in Blender is also Z? HOW??
he hit numpad 7 i think
What is the advantage of doing it here in unity in c# rather than in blender or other animation software?
I think because the ik system in unity is different than in other animation software imo
Oh wow. Inverse kinematics doesn't seem so intimidating anymore. It's pretty much just calculating the normal between the target position of the end effectors and the joint that you want to move, and maintaining the distance of the joints.
ngl this tutorial is long but it is epik
P E R F E C T !!!!!
But why are you talking about shadows for an ik solver?
Thx Dude Now by Getting Yur Inverae kinematic i mean Wathcing the Full tutorial I can create a Balance Character
so can i use this to make weapon contact in a fighting game?
How am i supposed to animate if i can view it in the editor>
Hi could I use this Ik to make a bendable sword that bends like a fencing blade against a target in real time physics ?
yes you can
@@kurtisgibson2929 Hi Kurtis i have spent hours trying to recreate that ik actin on my sword but cant get it to work any ideas ? Hugo czcams.com/video/3ViP0cwIyPE/video.html
When I look around in game, the arm keeps twisting with it
How to use it on top of an existing animation;
Like, use leg ik in waking animation
there's a package from unity that does that, it's called animation rigging
you are fucking awesome man
where the influence come at play i dont want the influence to be always at 1 but im dumb so i dont understand where to use to smothly go to the ik target
Maybe look in to 'easing movement' through code? that might be what you are looking for
@@daanvanleeuwen8435 i solved by using a linear interpolation (vector3.lerp) between the actual transform of the foot and the target position of the ik with a variabile that increase or decrease following a curve in the animation. so with the foot is up its at zero when the foot goes down it increase to assigning the target position. it works not perfect but it works
THX
Thank you !!!!!! I would like to give you a donation
Do you know how we can import file robot arm solidwork 3d into unity ?
as fbx
cant wrap my hed around it
this is cool but his is one of my first times using blender and i have no idea what to do
Just wondering if it would be ok if I can modify your code?
Yes
Omg yes!!
IT WAS REALLY NICE TUTORIAL! But I'm russian so I didn't understand much....
What i dont understand is how will this make my enemy walk? what do i have to move to make it walk. Im so lost lmao
@@littledumpling5614 Let me know if u ever figure it out haha
@@littledumpling5614 Yea I really have no clue how this can make things walk...
czcams.com/video/e6Gjhr1IP6w/video.html
Can this work for rope physics?
Every time someone does something in blender, they fly around and I'm completely lost. I have to pause every couple seconds, research how he did each step
Powerful tool, but very unintuitive
Here's a good one for creating / working with bones
czcams.com/video/ZmiZ6VkSJBE/video.html
Hey watch these videos lol (~22min total)
czcams.com/video/U1f6NDCttUY/video.html
this is math or physics ? please someone help
dude rotation part was so fast and i coldn't understand what you doing :(
and you just skipped the back strength stuff, can anyone explain why we lerp with back strength thing
Yo man awesome job, btw i was able to twick alil bit the code,
and made it run at least for now (without a pole) 4 times as fast.
hmm like per 10k runs, the code dropped from 300ms, to about 80 ms , with 4 chain length.
13:09 (notes for me)
Noice
yES