Active Ragdoll / Physics Animations in Godot 4.0

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
active ragdolls are a great way to get characters to interact naturally with the game environment without having to add a bunch of extra animations in this video I'm going to cover how I was able to get an active Ragdoll implemented in Godot 4.0 that could also play traditional animations imported from blender first we need a rigged model with animations here I'm reusing the rigor setup for the Leviathan ax video is essentially a miximo y bottle some animations that I merged together in blender we're going to need two of these one will be the active Ragdoll and the second will play the animations that we want to copy give them names to help differentiate them here I'm just making them both local to the scene just so I can edit them in the main scene to make the video a little easier to record set an animation to play on the animated rigs animation layer now let's set up our Ragdoll click the physics rig skeleton 3D node then in the toolbar at the top click the skeleton 3D button and click create physical skeleton this will create our physics bones for us now clean up the generated bones if you have a simple rig this will be way easier but if you have a complicated one like I have for miximo you'll need to spend some time tweaking the bone collisions and removing bones aren't needed like the ik pole bones once you're happy with your bones select them all and set the joint type to generic Six Degrees of field joint this will give us the most control over our joints attach a script to the skeleton and add this line of code to start the Ragdoll simulation when the game runs try running now and see how the Ragdoll looks if it behaves strangely then you need to keep tweaking the bone Collide sizes and Joint parameters you can alter the joints X Y and Z limits per bone to allow for more natural range of motion once you're happy it's time to start working on getting the Ragdoll animated to get our Ragdoll to attempt to match the animation playing from our reference rig first we're going to have to find the difference in position and rotation of each physics bone and their animated rig counterpart and secondly apply physics forces to move them into the correct position I was originally planning on using the generic Six Degrees of field joints spring constraints to achieve the latter part for us but after trying and failing to get these values to actually do anything for a while I dived into the engine code to see what was going on and found out they just weren't implemented in 4.0 yet oh well we can achieve this ourselves pretty easily using hooke's law and the physics bones linear and angular velocity properties hooke's law is very simple we can calculate our spring Force by multiplying a stiffness value by the displacement of the spring displacement in our case means difference between our current and Target positions this alone will make a spring that moves back and forth forever we can apply some damping by subtracting a damping value multiplied by our current velocity from the previously calculated spring Force put this hooke's law function into the script we created earlier and Export some stiffness and damping variables create a set for both linear and angular movement while here let's also export a variable for our Target animated skeleton to help see what's going on I'm moving the animated rig to be a child of the physics rig and move them to overlap I'm then setting the animated rig to be slightly transparent for a ghosting effect back in the script create a variable to hold all of our physic bones in the ready function get all children of type physics bone 3D and put them into the physics bones variable then in the physics process function Loop over our physics bones we can get the animated bone and physics bones current pose information by calling the get bone Global pose function even though the function has the name Global in it the transforms that gets returned aren't actually Global it's relative to the skeleton the bone is from physics simulations tend to run in global space though so we can easily make the transformation Global by multiplying the skeleton's Global transform with the pose data okay let's handle the linear forces first to calculate the displacement needed for hooke's law take the target transform position and subtract the current transform position from it we can now just pass all our data into the Hook's law function to calculate our Force then we can just add it to the Bone's linear velocity value that's it now let's sort out the rotation we can calculate the rotation Difference by multiplying the target poses basis or the inverse of our current poses basis we can then use the get Euler function to get this value in vector-free format then pass all the data into the hooke's law function just like we did before and apply the resulting force or Torque in this case so the Bone's angular velocity and that's all it takes just like the bones themselves it can take a lot of tweaking to get the spring values feeling nice and it really depends on how realistic or cartoon you want it to feel I found that these values worked well for me if you want to add an even further level of control we can hide the physics rigs mesh too and add a third rig that will interpolate between the animated physics rigs poses attach a script to this new interpolated rig skeleton this script is very similar to the physics skeleton script except we iterate over every bone in our skeleton and we use the set bone Global pose override function as we mentioned before poses a relative to their skeleton not the world we can use the global transform.ifying inverse function to achieve this this should give you a good base to build on of your own implementations there's some further ways you could improve this like a way to stop the physics Bones from getting trapped in the world geometry I'm really interested in hearing your ideas please put any suggestions you have on how you'd improve this system in the comments below I think that about does it for this video I hope you found this useful a GitHub project with the code you've seen here will be linked in the description below as well as any resources I found useful I decided to try streaming some of my Godot 4.0 experiments on Twitch so if you're interested in this please send me a follow link to my channel is in the description also don't forget to drop a like And subscribe if you like the video anyway I'll see you in the next one cheers
Info
Channel: Crigz Vs Game Dev
Views: 41,332
Rating: undefined out of 5
Keywords: Godot, Godot 4.0, Godot 4, Active Ragdoll, Ragdoll, Physics, Procedural Animation
Id: 0MHY2TDeMLM
Channel Id: undefined
Length: 6min 6sec (366 seconds)
Published: Sun Mar 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.