Realistic Legs in Godot - IK Legs Tutorial (godot 3.X)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey so do you ever play games like horizon forbidden west or breath of the wild and think god damn those are some nice legs yeah me neither but i did notice link's legs doing something none of mine had ever done before in godot they adapt to the slope that link is standing on which is pretty cool this is called inverse kinematics and i'm gonna try and show you how to get this set up in godot so you two can have lanky legs like link first things first you're going to want a player i'm assuming you have a mesh with a skeleton and some animations already i have this robot guy with some animations that i downloaded from adobe miximo i am also not going to go over any character controller or other animation stuff here there are some great tutorials about animation trees and blending and character controllers and whatever else that i use here but we're just gonna go over some ik legs okay so when you have a character with the animations imported into the editor we can get started godot actually has built-in functions and nodes for ik so we're going to be using them on your skeleton we can go ahead and add the skeleton ik node for each leg and assign the root bone as your upper leg or thigh bone and the tip bones as the foot or toe bones this won't do anything by itself as the skeleton ik node has no target so add two position 3d nodes and name them target left and target right and then assign these as the targets in the skeleton ik nodes [Music] also make sure to turn on the use magnet option and give it some attraction on the forward axis so your knee bends the right way that's all for setting up the ik node but as you can see when we run this the foot is a bit twisted up so to fix this just rotate the target nodes until it looks right so now we have ik working on our legs but nothing's gonna happen when we run the game because we're not telling the game where the ground is below each foot or to update the target's location appropriately to sort this out we're gonna need to do a bit more work i'm afraid i'm gonna add a few new nodes here firstly a raycast for each leg which will check if the player is near the ground and where the ground is relative to the player [Music] i'm also going to add two new position 3d nodes called no raycast pods left and right which will be used as the target when the raycast isn't colliding with the ground [Music] as well as this i'm just gonna add two position 3d nodes called interpolation left and interpolation right and the y position of this will control the interpolation which is a value on the skeleton ik nodes that control how much of an effect the ik has on each leg i'll explain why i'm using a position 3d instead of directly changing these values and why we need to change these values at all later so now for some coding i've attached the script to my root node of my model uh the first step is to assign some variables such as our minimum and maximum interpolation values the foot height offset which is just how tall the foot is roughly and a variable for each of the nodes we have added target left target right raycast left raycast right ik right ik left no raycast pods left and no brake ass paws are jesus i don't envy people who have to explain their code on a daily basis we also need to start the ik simulation which i will do in the ready function now i just created the function that will update the ik target positions i'm going to call it update ik target position this function is going to need the target raycast no raycast position and foot height offset in the function we're gonna check if the raycast is colliding if it is we will find where it's colliding on the y-axis and assign that as a new variable called the hit position we then just set the target's y position to be the same as the hit position essentially making it so the target is going to be exactly where the ground level is if the raycast isn't colliding then we'll just set the target's position to the no raycast position now in the physics process we can run this function for each foot and assign the relevant variables [Music] let's see what happens when we run this now we can see that this works the legs are adjusting to the ground height and slope but there is a slight problem they all but completely override the animation and the feet just slide across the floor it's not the effects we want that's where our interpolation values come in we need to animate the interpolation nodes y location to fit when we want the ik to be turned on so we need to do this for each animation i'm just doing this using the bezier curves in the animator the interpolation value is set to one where the foot is touching the ground in the animation and zero when it's in the air with a small transition period [Music] i've also animated the targets z position to roughly line up with the foot at all points just so that the ik will always fit with the animation [Music] the reason we use the position 3d instead of directly animating the interpolation value is that when you may later want to be blending animations the positions blend smoothly compared to the set value which won't blend at all and not to forget we do need to just add these two lines of code to our script which will just set the interpolation value based off of the y value of our interpolation position this whole tutorial is such a mouthful geez once you've finished updating your animations then the ik legs are done here you can see my test model running the code and concept is really easily reusable in other projects and hopefully you've learned something new about godot this whole tutorial is essentially just building on watch tech pez's tutorial on the exact same thing but i've tried to go over a bit more depth because after watching that one it took me a good week to actually understand what was going on i still don't really know what this function that they use does but mine works fine without it so there you have it you too can now reach new levels of immersion watch as the crowds gasp at your legs adjusting correctly to the terrain you can proudly proclaim that yes godot is an amazing engine and yes you should subscribe to leon stansfield i hope you enjoyed this video if you do get stuck or i forgot something just leave a comment the source code is in the description [Music] goodbye editedly on here i just thought i'd give 30 seconds to just do an update of what i'm actually working on uh i finished that horror game i made a video about but i don't think it's good enough to publish so i'm gonna sit on that for a few months and and maybe come back to it later i'm a bit bit fed up with working on that one as well as that i entered the bullet hell game jam and amazingly i came 22nd out of 300 and something which i was really damn pleased with you know i'm gonna put that on my cv um and i've always got new ideas coming around my head i'm always working on something so hopefully i'll have some new content soon
Info
Channel: Leon Stansfield
Views: 29,641
Rating: undefined out of 5
Keywords: tutorial, godot, realistic foot ik, unity foot placement realistic, unity realistic foot placement ik, blender tutorial, godot steam game, inverse kinematics tutorial, inverse kinematics tutorial 3ds max, rigging tutorial, procedural tutorial, unity tutorial, blender rigging tutorial, unity procedural tutorial, ik tutorial unity, godot devlog, blender 2.8 tutorial, blender 2.9 tutorial, botw, Breath of the wild, Breath of the wild in godot, procedural animation, Godot IK
Id: 8a7_2remjIg
Channel Id: undefined
Length: 8min 56sec (536 seconds)
Published: Wed May 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.