Do you also have a YouTube Channel? It would be great to subscribe to your feed. Cheers. Reshared on r/VisualSchool. I hope it doesn't bother you. Cheers!
This is pretty much how I do it with unreal, But I calculate the ground distance and interpolate the pelvis bone. In my case, the character has a higher velocity so changing the pelvis bone along with the legs gives me a good output, Sorry I cannot share the character due to NDA. you did an amazing job ty <3.
There are some slightly complex techniques, but for humanoids you can always use unity’s built in stuff. Look up “unity inverse kinematics” and you’ll get a lot of tutorials
Thanks OP, always wanted to do some IK, so I gave it a whirl. Doesn't look nearly as good, and I still need to figure out how to properly do step 8 (probably why he likes to hop so much), but there you go: https://i.imgur.com/HhjxplN.mp4
The rest of it is just manipulating the transform of the leg or body somehow in code.
For example, the legs knowing when to walk could cache a reference to a Boolean in an opposite leg that is switched when the leg is down, only allowing itself to go up when the opposite leg is down.
Then for things like the little running sphere: create a sphere object prefab. Cache a reference to it in the leg (one for each leg) then do a if (Vector3.Distance) check to see if the two are too far apart, and if so lerp the leg to the sphere.
Finally, for the body rotating slightly, cache a reference to just one leg (any) in the body script.
Check constantly if the leg is up or down and then lerp the rotation around the z axis one way or the other.
I don't think you'll need an actual sphere prefab haha, that was just for demonstration. Simply attaching an empty to the body and raycasting downwards to find the next leg target should do. Also for the z rotation, I'm comparing the average of all left legs to the average of all right legs :)
I wish more tutorials were like this. So many tutorials spend so much time muddling the concepts with minutia that you can't figure the high level concepts that actually matter.
HI WELCOME TO MY TUTORIAL TODAY THIS IS A TUTORIAL STICK AROUND TO SEE MY TUTORIAL --40 second intro sequence in 4:3-- HI THIS IS MY TUTORIAL IM REALLY EXCITED TO GIVE YOU THIS TUTORIAL TODAY BE FOR TO SMASH THAT LIKE BUTTON AND SUBSCRIBE AND RING THAT BELL AND WRITE IN THE COMMENTS WHAT YOUR MOTHER ATE TODAY OK NOW LETS GET ON WITH THE TUTORIAL THIS IS A TUTORIAL I'M REALLY EXCITED TO SHOW YOU THIS TUTORIAL
I don't know what would be worse: If it was slowly typed out on notepad in the video with no audio commentary or if their mic quality was awful with a horrendous loud buzzing on top.
"Hey guys so I know I haven't uploaded recently but I promise I'm going to get back on track, it's a long story about how my cat has been sick and I'm going to tell you all the details just so you know ..."
So I'm guessing you position the legs manually in a zigzag pattern before running to prevent the legs from wanting to move at the same time (and also to mimic the realistic behavior).
I was wondering, since the zigzag pattern was enforced only once before runtime, if the pattern would change over time based on obstacles and rotations?
Yea I'm offsetting the legs at the start based on the step distance. You're right, normally the pattern would change over time and they would start to hop around. That's where the check for opposite legs comes in; by checking if the opposite legs are grounded before taking a step it keeps the same pattern.
I literally came across this last night and I’ve been obsessed with procedural animations since then, then OP posts this! Man you guys are in my head right now lol
I love that this is high level only. It forces people to experiment and test things on their own and really learn it so that they can expand it in the future. I find I often lack the ability to expand things I've learned from step by step tutorials.
If you want to try writing your own inverse kinematics, it's surprisingly approachable. I just studied this a week ago and it's on my back-burner.
Forward-and-backwards reaching IK is simple in math terms (just addition and subtraction) - I'm sure it's not the fastest version of IK, and it's inherently inaccurate, but it is approachable even to a novice.
Point 6: moving the leg seems like more than one step to me (no pun intended). You have to move the leg up and over or something. I don’t get how you’d do that exactly
Yeah maybe that should've been 2 steps, it uses MoveTowards() and during the first half of the step I'm adding an upwards vector to the target position to get that curved step motion.
This is sort of an unrelated question, but I’ve been meaning to ask it for quite some time now, why is it that in these kinds of videos everything always looks so pleasant in terms of the lighting but when I use unity any lights I try to use and settings I try and change end up looking either too harsh or i guess in a way too realistic for my non realistic looking game objects. I suspect it is because the materials used in these videos have unlit shaders on them? But I could be wrong, I am just a beginner. Any tips or tricks would be much appreciated. Oh and love all your videos on procedural animation by the way, thank you for posting them.
This demo only has the default directional light and all objects are using the standard shader so I'm not really sure what would cause it to look different from your scene. Some post processing may help to make your scene look better :)
How do you deal with potentially conflicting rules?
For ex) move pair of legs only when others are on the ground && move legs when raycast point goes to far. It feels like adding too many rules like this would cause breaks.
It doesn't really have any conflicting rules; once the distance between ik point and ik target is big enough it starts checking the opposite legs. Then it simply waits until the opposite legs are grounded and takes a step. If in the meantime the distance gets smaller again that's not an issue because it just stops checking the opposite legs and the leg will stay grounded.
Hey, what I found works pretty well is to first rotate the body towards the movedirection by comparing current position and last position, and then overwriting the z rotation based on the difference between the average height of the left legs and the average height of the right legs.
u/happygamedev Hey, how are you moving the leg towards the target? I am using Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta) but it snaps instantly unlike yours which is very smooth
It completely depends on your preference, you can either model and rig directly in Blender and setup fast ik in Unity, or model just the seperate parts in Blender and setup both the rig structure as well as fast ik inside Unity.
It doesn't have any joints (no joint components), the bottom part is parented to the middle part and the middle part is parented to the upper part. Then if you put the Fast IK controller on the bottom part it should work.
The legs are parented to the body and the IK overwrites the leg positions. It stays on the ground because the legs use raycasting to stay grounded and the body updates based on the average leg position.
This is the code i use to move the feet. I've parented the legs to the body but now the whole of leg moves with the body. I can't figure out how to fix this.
I'm storing the world space positions of the legs so they can be overwritten in lateupdate. That way the leg won't move with the body except for when it takes a step.
How can I override the position? also turns out the script making the feet move doesn't work doesn't work, the feet is continuesly moving to the target.
Also how do you have the legs set up, the ik script at the end of the leg (feet) or the start of the leg? I've been having two different outcomes none of which work well.
The IK script is attached to the foot and controls the other leg parts further up the hierarchy. The entire thing is parented to the body and then the IK overwrites the body movement.
You need to set the foot position to the stored world position every LateUpdate() call, even when you're not moving the leg to a new location. That way it overrides the body position continuesly.
I just can't get it to work. The whole limb just follows the body. The ik isn't overwriting the movement. Its because of the target moving with the body. Is there some way i can send you some footage of it?
What a helpful breakdown. Programming is all about chunking an end result down to individual steps, and often times those steps are either not apparent at all, or take lots of trial and error to find on your own. Thanks for sharing!!
FYI, the source engine (not gold source) does this for walking and running animations in Half Life 2, its expansions, Counterstrike Source and Global Offensive, and some others.
Aren’t raycasts supposedly very performance heavy..? So calc raycast for each leg and then multiple spiders.. How much of a difference would it make if we used normal animations instead.?
It first rotates towards the move direction (comparing last frame's position and current position) and then overwrites the z rotation (forward) by subtracting the left and right leg height.
114
u/happygamedev Mar 28 '20
For examples of how I'm using this kind of procedural animation in-game, check out my twitter.
28
u/Kadilack5 Mar 28 '20
How do you use inverse Kinematics to move the legs in that way? Are they like childs of each other or something like that?
12
u/flait7 Mar 28 '20
I think each of those steps might need a 10 step tutorial
6
u/Dicethrower Professional Mar 28 '20
Thanks OP, always wanted to do some IK, so I gave it a whirl. Doesn't look nearly as good, and I still need to figure out how to properly do step 8 (probably why he likes to hop so much), but there you go: https://i.imgur.com/HhjxplN.mp4
33
u/[deleted] Mar 28 '20
This feels like a rest of the fucking owl situation just because I have no clue how to do any of this.
3
u/JuliusMagni Programmer Mar 28 '20
Wow this is awesome.
As for IK, how is that setup? In the animator?
166
u/abccbaccabccbabb Mar 28 '20
Thanks for posting. I love this stuff in games and I always wondered how it was done
159
u/Scatoogle Mar 28 '20
I wish more tutorials were like this. So many tutorials spend so much time muddling the concepts with minutia that you can't figure the high level concepts that actually matter.
2
u/Dexter1272 Mar 28 '20
Not using Unity but developing on other engine but this general-knowledge is awesome.
2
u/DeJMan Professional Mar 28 '20
So I'm guessing you position the legs manually in a zigzag pattern before running to prevent the legs from wanting to move at the same time (and also to mimic the realistic behavior).
I was wondering, since the zigzag pattern was enforced only once before runtime, if the pattern would change over time based on obstacles and rotations?
2
u/theviper14 Engineer Mar 28 '20
Thank you for sharing! I have a quick question, how are the legs raised when they move from initial position to target position?
2
u/adamMorsky Apr 03 '20
I think you've started an epidemic u/happygamedev. One that I am absolutely ok with.
2
u/codemonkey13981 Aug 04 '20
I think I just learned more about a Unity concept in 65 seconds than I have in years of practice.
111
u/Andrew_Kite Indie Mar 28 '20
I always wondered how you managed this. And to see how straight forward the logic is...
Nicely done!
14
u/Segphalt Mar 28 '20
Another great resource https://youtu.be/LNidsMesxSE
9
u/Bernhelm Mar 28 '20
Great explanation gif! Thanks!
8
u/Moorific Mar 28 '20
I love that this is high level only. It forces people to experiment and test things on their own and really learn it so that they can expand it in the future. I find I often lack the ability to expand things I've learned from step by step tutorials.
7
u/fishboi9 Mar 28 '20
Dude out here really making walking mailboxes, respect +
5
u/vertex_whisperer Mar 28 '20 edited Mar 28 '20
If you want to try writing your own inverse kinematics, it's surprisingly approachable. I just studied this a week ago and it's on my back-burner.
Forward-and-backwards reaching IK is simple in math terms (just addition and subtraction) - I'm sure it's not the fastest version of IK, and it's inherently inaccurate, but it is approachable even to a novice.
1
u/ImNotAfred Mar 28 '20
Ad 6. How do you move the leg towards the target? Via animation? Via some spherical interpolation or what?
1
u/Kowarenai Mar 28 '20
Is this done within the Mecanim scripts or in a MonoBehaviour? Thanks!
1
u/EEON_ Novice Mar 28 '20
Point 6: moving the leg seems like more than one step to me (no pun intended). You have to move the leg up and over or something. I don’t get how you’d do that exactly
1
u/Krimble-Scrumbus Mar 28 '20
This is sort of an unrelated question, but I’ve been meaning to ask it for quite some time now, why is it that in these kinds of videos everything always looks so pleasant in terms of the lighting but when I use unity any lights I try to use and settings I try and change end up looking either too harsh or i guess in a way too realistic for my non realistic looking game objects. I suspect it is because the materials used in these videos have unlit shaders on them? But I could be wrong, I am just a beginner. Any tips or tricks would be much appreciated. Oh and love all your videos on procedural animation by the way, thank you for posting them.
1
u/fappaderp Mar 28 '20
How do you deal with potentially conflicting rules?
For ex) move pair of legs only when others are on the ground && move legs when raycast point goes to far. It feels like adding too many rules like this would cause breaks.
1
u/0xb074 Mar 29 '20
How can i fix some object end to the ground but keep the rotation? (Step 2)
1
u/TheRolf Programmer Mar 31 '20
Can you develop step 10 ? I know you want to rotate the body but you have 4 legs or more so how do you do that ?
1
u/DrakeSingh Apr 14 '20
I just want to clear one thing. In step 1, is red dot the target of IK leg or the point you are moving?
1
u/spawnofdexter May 23 '20
Hey, can you please tell me if you model these in Unity, or do you use Blender or something like that?
1
u/LolzForPolez ??? Jun 15 '20
how did you create the model, i cant get joints to work properly
1
u/LolzForPolez ??? Jun 15 '20 edited Jun 15 '20
How do you keep it attached to the body? Also how do you keep it on the ground?
EDIT: i have made it so the 'feet' go to the target but I'm stuck on how you keep the start of the limb stay on the body.
1
u/edog37 Mar 28 '20
Can we pls get a tutorial
3
u/EBKey Mar 28 '20
Amazing i love these kinds of gif short-tutorials, so efficient. Worth of a 10 minute video or even more read.
3
u/[deleted] Mar 28 '20
Can I just say you are fucking amazing
2
u/[deleted] Mar 28 '20
I love educational posts like this
2
u/[deleted] Mar 28 '20
Super well explained! Even as a pleb I understood how it works after this :)
2
u/tonyg3d Mar 28 '20
That's brilliant. Thanks so much for the easy clear explanation. I just wish I could program. 🙁
2
u/shizola_owns Mar 28 '20
Great explanation
2
u/dayzdayv Mar 28 '20
What a helpful breakdown. Programming is all about chunking an end result down to individual steps, and often times those steps are either not apparent at all, or take lots of trial and error to find on your own. Thanks for sharing!!
2
u/[deleted] Jul 05 '20
Fucking amazingly described. That's true eli5 right there (at least for us devs). I'm going to be testing this out asap.
1
u/PrinceNelson 14d ago
This is the future of games and so few prioritise it.
1
u/Rainbow_Guppy Mar 28 '20
This is great! Thank you for sharing!
1
u/m3l0n Professional Mar 28 '20
Thank you, it's always seemed like witchcraft to me!
1
u/alanmthomas Mar 28 '20
Thank you thank you! This is great!
1
u/GameCollaboration Mar 28 '20
Very cool man. Thanks for taking the time out of development to help others.
1
u/Teej_544765534454 Mar 28 '20
Thank you brother
1
u/nosyrbllewe Mar 28 '20
For people unsure if how to do the IK, I recommend looking into the new Animation Rigging package as it allows custom IK rigs.
1
u/birthnight Mar 28 '20
This is seriously the best tutorial format! Thank you!
1
u/[deleted] Mar 28 '20
Aaaaaaa! Not only a great cheat sheet but rendered with style
1
u/MechwolfMachina Mar 28 '20
Well, this newbie game dev learned something new today! Thanks for putting this together
1
u/FoHeim Mar 28 '20
Very cool and looks so seamless in motion
1
u/bMind_ Mar 28 '20
That's really simple and approachable way of presenting the problem! Thanks for sharing!
1
u/pachermann Mar 28 '20
Very nice thank you! Would love to have tutorial can be paid course.
1
u/[deleted] Mar 28 '20
Thanks this makes me want to open up unity again and try some stuff :P
1
u/roby_65 Mar 28 '20
For humanoid avatars walking, it this the same principle? Is there any drawback for using unity built in IK?
1
u/[deleted] Mar 28 '20
Amazing! This does really help and it seems so much easier than I thought.
1
u/Midnight-sh_code Mar 28 '20
this is an amazingly done video. thank you so much
1
u/b4cksp4c3 Mar 28 '20
This is gold. Thank you.
1
u/pkjak Mar 28 '20
Wow, my initial procedural spider that doesn't go around walls uses pretty much the completely same approach. Nice video.
1
u/RobinYiff Mar 28 '20
FYI, the source engine (not gold source) does this for walking and running animations in Half Life 2, its expansions, Counterstrike Source and Global Offensive, and some others.
1
u/Youles Mar 28 '20
This was super helpful!
1
u/jl2l Professional Mar 28 '20
very cool
1
u/StBlaize Mar 28 '20
Yeah you need to start a YouTube channel please
1
u/M374llic4 Mar 28 '20
A+ tutorial. I would love more like this, lol.
1
u/anime-username Mar 28 '20
Aren’t raycasts supposedly very performance heavy..? So calc raycast for each leg and then multiple spiders.. How much of a difference would it make if we used normal animations instead.?
1
u/chillaxinbball Mar 28 '20
Kool. Now add physics.
1
u/JotaRata Intermediate Mar 28 '20
This is so f*cking cool, im gonna save it
1
u/[deleted] Mar 28 '20
Saved for a time when I am much better at C#. Thanks!
1
u/Sweet--JP Designer Mar 29 '20
Step 6, move leg, that's still an animation clip or what?
1
u/[deleted] Mar 30 '20
Noice
1
u/imHrvaT Apr 07 '20
can you please share the source code??
1
u/unitcodes Apr 21 '20
Such a Beautiful Explanation
1
u/[deleted] Aug 18 '20
Can this be used for climbing and transitioning between animations?
1
u/Timesplitting Nov 10 '21
This is really inspirational! Thank you for sharing (a year later)!
1
u/weizXR Oct 26 '22
We need more videos like this for tutorials; Step by step, visual, and to the point.
1
u/Impossiblevrsharkey Dec 28 '23
codeer?
1
u/probably_not_bro Programmer Feb 12 '24
did you use any unity asset for the inverse kinematics. if so then what is it. i can't see any proper tutorial on how to code inverse kinematics.
1
u/K3nway93 Mar 28 '20
best tutorial i ever seen!
0
u/[deleted] Apr 09 '20
[deleted] — view deleted comment