YouTube2Text

NEW Procedural Animation In Godot 4.0 — Transcript

by Crigz Vs Game Dev · 1,738 words · 113 segments · language en · Watch on YouTube

Full transcript

  1. 0:01With the removal of the SkeletonModificationStack from Godot 4.0
  2. 0:05I’ve received a few requests to update my tutorial.
  3. 0:09In this video I’m going to show you how to create an improved procedurally animated spider bot
  4. 0:13that is fully controllable and can walk on rough terrain, walls and ceilings.
  5. 0:18The first step is to have a model that’s been rigged.
  6. 0:20I’m using this quick one I threw together in blender,
  7. 0:23If you want to follow along with the video, I’ll put a download link for the model in the description.
  8. 0:27Now in Godot, I’ve created a simple room in the main scene using CSG nodes.
  9. 0:32I’m now creating a new inherited scene from the blender model & updating the materials
  10. 0:36so it looks a little nicer.
  11. 0:38Now let's get the IK set up.
  12. 0:40As I mentioned in the intro, the SkeletonModificationStack was removed from 4.0.
  13. 0:44Either they’ll re-add an improved implementation in a later version, or we’ll get something new entirely.
  14. 0:49For now though we need to use the deprecated SkeletonIK3D node.
  15. 0:53Add 4 SkeletonIK3D nodes to the Skeleton node,
  16. 0:57one for each leg on our robot, and set up the chain.
  17. 1:00There’s a strange behaviour where only the bone before the tip bone will point at the target,
  18. 1:05but in our case we actually want the last bone in the chain to do that.
  19. 1:08To work around this I added an extra bone to the end of the bots legs in blender
  20. 1:12that has 0 weighting for mesh deformation and set that as our tip bone in Godot.
  21. 1:19The root bone is the third bone up from our tip.
  22. 1:21We also want to use a magnet force with the value set to 10 on the Y access to keep our legs pointing upwards.
  23. 1:28Set this up for each leg.
  24. 1:30Now let's set up 4 nodes to act as our IK targets.
  25. 1:34I’m using Markers to make them visible in the editor.
  26. 1:37Adjust their position until you’re happy with the default pose.
  27. 1:40We need to attach a script to our IK nodes to start the IK simulation when the game is started.
  28. 1:45We can add tool to this script so the IK runs in the editor too,
  29. 1:49which makes finding the right positions for the targets easier.
  30. 1:52Get the targets into a place you're happy with!
  31. 1:54At the moment if you move the scene's root node, the IK targets will move too.
  32. 1:58We can set the transform to top-level so they will ignore the parents' movement when the game is ready.
  33. 2:05Let’s add a script to our Robot so we can move around.
  34. 2:08Attach a script and at the top export two variables to hold move speed and turn speed.
  35. 2:13Then in _process lets get our input directions then translate & rotate accordingly.
  36. 2:18You may wonder why I’m using rotate_object_local, instead of rotate_y.
  37. 2:22Using rotate_object_local like this means we’re rotating around the local y axis of the object, regardless of its global orientation.
  38. 2:31This means it will work while we're standing on the wall or upside down.
  39. 2:34Now let's add our bot to the main scene and try it out!
  40. 2:45To handle walking, our IK target is going to track its distance to a “Step” target.
  41. 2:50Unlike our IK target, this step target move will not be top level, so it will move along with our spider.
  42. 2:56If the distance gets too far, we’ll move our IK target to the step target's position.
  43. 3:01Let's begin by setting up our step targets.
  44. 3:03First I’m going to add a node 3d called StepTargetContainer, which we’ll need for later.
  45. 3:07To make things quicker, I’m copying the IK target nodes, removing top_level & renaming them to StepTarget.
  46. 3:14We want our step target to always align with the floor,
  47. 3:16so I’m then positioning ray cast nodes at the step targets, angling them slighting and moving them up.
  48. 3:23The angle helps when attempting to walk up 90 degree surfaces.
  49. 3:32To position our step targets to the floor, create a new script and attach it to the rays.
  50. 3:36Get a reference to the step_node for the ray and in physics_process, if a hit point is found, move the target to the hit location.
  51. 3:45Then in the editor, set the step target references.
  52. 3:49Now attach a new script to your IK Targets, this script will handle the animating of the target.
  53. 3:55At the top add two variables, one is a reference to our step target, the other is our distance between taking a step.
  54. 4:02Then add a new function called step.
  55. 4:04Like before, we’re going to use tweening to animate the target.
  56. 4:08This is the tweening logic from the old implementation.
  57. 4:11It was overly complicated and only lifted the leg upwards globally on the Y axis, which ruins the effect while walking up vertical inclines or while upside down.
  58. 4:20I’ve now simplified the tween to this:
  59. 4:23We get our target position, and then find the halfway point between it and our current location.
  60. 4:29Then we tween to the halfway point plus our owner’s, which is the spider bot’s, basis.y.
  61. 4:34This will be one metre up in whichever direction the spider is currently oriented.
  62. 4:39Once we reach that target, we then tween to the final target position.
  63. 4:44Finally, in process, check the distance between the target and our current position, and if we exceed our required value, call step.
  64. 4:52Let's see how that looks.
  65. 4:54Well, it works, but all legs are stepping at the same time.
  66. 4:58Let’s make it so we can’t step if the the adjacent leg on the left or right is already stepping.
  67. 5:04Back in our script, add a reference to our adjacent leg, and a boolean to track if we're currently in the stepping state.
  68. 5:10Then add to our if statement, to only step if
  69. 5:131, we aren’t already stepping, and 2 if the adjacent leg isn’t stepping.
  70. 5:18Then in the step function, set is_stepping to true. Then lets add a callback tween to the end of our tween queue.
  71. 5:25For the callback, we are going to use a lambda function to set is_stepping back to false after the step is complete.
  72. 5:32Set the adjacent references and let’s take another look.
  73. 5:35That’s much better! But personally, I like it when the legs diagonally step at the same time.
  74. 5:41If you want to implement that too, let's add another reference for our diagonally opposite leg, and then when we call step, call step on the opposite leg too.
  75. 5:50Muuuch better! This looks great while turning around, but when walking the legs lag behind a bit.
  76. 5:56Let's fix that now.
  77. 5:58Add a new script to our step target container.
  78. 6:00Add a variable to the top to store our desired offset when moving,
  79. 6:04lets also grab a reference to the parent node & store the parents previous position.
  80. 6:09Then in _process, we can calculate the velocity by subtracting the previous position, from the parents current position.
  81. 6:16We can then set our container's position using this velocity multiplied by our offset.
  82. 6:21Finally update our previous position variable.
  83. 6:25This is looking way better! We just need to get our body moving & rotating based on the leg positions now.
  84. 6:31Back in our main spider_bot script, let's first move our movement logic into another function for neatness.
  85. 6:38Then let's add some references at the top to hold our legs IK targets.
  86. 6:42Let's also create a variable to hold our desired height offset from the ground.
  87. 6:46In the old video I used the following logic to handle the rotation, taking the average leg positions and using the difference to calculate rotations on the relevant axis.
  88. 6:56This method works great until you go vertical or upside down, and then it quickly falls apart.
  89. 7:01I had to come up with a solution that would work for any orientation, that’s when I remembered my old friend, the Plane class.
  90. 7:08A plane is essentially a position and a direction, also known as a normal, that has various uses.
  91. 7:14One way we can initialise a plane is by putting in 3 positions in clockwise order.
  92. 7:20My idea was to create two planes from the ik target positions. Then, we can average the normals to get our bodies desired orientation.
  93. 7:29We just then need to be able to turn this normal into a transformation basis.
  94. 7:33We can do this in a similar way to how we did it in the path-based mesh generation video.
  95. 7:38I’ll skip the explanation on the basis's, as I already went over it in that video.
  96. 7:43Our new basis’s y is the normal direction, its x is the normal crossed with our forward direction, and the z is the right direction crossed with the normal direction.
  97. 7:54Finally, let's overwrite our basis with the newly calculated one.
  98. 7:58We can use lerp too to make this smoother. Let’s check the result!
  99. 8:02Awesome! We’re almost there. There’s just one last thing we need to do.
  100. 8:05We need to make sure we lift the body up and down based on the height of the ik targets.
  101. 8:10Let’s calculate the average position of the legs.
  102. 8:13Then calculate the target position as this average, plus our bots up direction, multiplied by our ground offset.
  103. 8:20Now we only care about the difference between our current position & the target position in the spider bots current direction, we can calculate this by using the always helpful dot product.
  104. 8:31If we take our direction, call the dot function and pass in the target position minus our current position, we’ll get only the difference for that direction!
  105. 8:41We can then lerp towards our position plus our up direction multiple by our calculated distance,
  106. 8:46this will work no matter which way our spider bot is oriented!
  107. 8:50And then we'll have the final result. There are few things we can do to improve this, but I'll leave it up to you in your imagination.
  108. 8:56Anyway, I think that’s about it for this video. I hope you found that useful.
  109. 8:59I’ll leave a github link to the finished project in the description below.
  110. 9:03If you found this video useful, please give it a like and think about subscribing!
  111. 9:07In a future version of godot has killed this implementation again, let me know and I’ll do another updated video.
  112. 9:13I’ve recently started streaming my Godot tinkering on twitch, if you want to see my fumble at both streaming & coding simultaneously, be sure to send me a follow.
  113. 9:22Anyway, I’ll see ya in the next one. Cheers!

About this transcript

This page contains the full transcript of NEW Procedural Animation In Godot 4.0 by Crigz Vs Game Dev, generated from the public captions YouTube serves with the video. The transcript has 1,738 words across 113 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.