@robotgrapefruit

583 227 331

Listen to this Thread


View original tweet on Twitter

Hide Media

Last weekend I posted a video of the duck I’m making with procedural animation, and the response was really encouraging! Some of you were asking how it’s made, so I thought I’d make a little breakdown of the setup! 🧵 #gamedev #unity3d #ducks

Disclaimer: I’m definitely not an expert on this stuff and there’s a ton of resources already about procedural animation, so I’m going to keep this pretty high level. Okay let’s go! I've grouped the setup into 3 main steps, with some smaller details between.

Step 1) Rig the legs with IK so the feet stay still when the body moves. I use Unity’s Animation Rigging package for rig constraints. It has some standard constraints that will be enough for most situations, but you can make custom ones if needed.

Ducks always look so squishy to me and I wanted mine to reflect that. So the rig doesn’t follow proper anatomy and many bones are separated so they can move independently. Each leg is just the foot and a single bone that morphs the body to imply a leg.

I can’t go over the whole rig, but I'll point out two important constraints I made. One adds rotation to the body based on the separation of the feet for some easy wiggle action. The other bends the toes at a secondary joint when the first has too extreme of an angle.

Step 2) Make a script that can perform a step given a target position and rotation. It should move the foot on a curve from its current pose to the new pose.

My duck’s feet have a few other features. I can change the speed of the step. Also the foot is prevented from going too far from the body. And when not stepping, if the body gets too far away, the foot clears its target and tucks in at max speed.

Step 3) Find each foot’s “preferred” pose relative to the body, usually using a raycast down to the ground from some point on the body. When the distance or angle is big enough between the foot and its preferred pose, tell it to step.

You can improve it by limiting the number of feet that are allowed to move at once, and step the foot that is farthest from its target. At this point you can move the body with scripts or whatever and it looks pretty good! I just have a few more details for some extra realism.

The duck’s body is a physics object and I move it only by applying forces. This allows it to push and be pushed by other physics objects. Joystick input applies horizontal forces, and a vertical force gets applied to keep it hovering above the ground.

The height it’s trying to hover at is based on the successful raycasts from the leg controller, and only applies if at least one foot is grounded. That way it can fall off ledges or trip if it can’t find footing.

To keep the body upright, I have a configurable joint with a slerp drive and configured-in-worldspace ticked. Then I can just set the joint's Target Rotation on the joint in a script to make it turn with physics.

Back to the feet, I mentioned before that they will tuck it their target is too far away. So I added a rule that a tucked foot will be told to step as soon as a new target pose is found, regardless of the other leg. This allows both legs to extend when landing from a fall.

Finally, I change the speed of the steps based on the body’s linear or angular speed. Also I don’t just raycast from the body’s current pose, but use its velocity to look ahead and cast from where it will be in one step’s worth of time.

And I think that covers the majority of the leg setup at the moment! I’m not sure if that made any sense at all, but I hope the gifs were entertaining at least 😅 I have a lot more planned, and I'm looking forward to sharing as I go!

If you made it this far thank you so much for reading! And if you learned something new from this or maybe got inspired to take a quack🦆at some procedural movement, I’d love to hear!

Last weekend I posted a video of the duck I’m making with procedural animation, and the response was really encouraging! Some of you were asking how it’s made, so I thought I’d make a little breakdown of the setup! 🧵 #gamedev #unity3d #ducks Disclaimer: I’m definitely not an expert on this stuff and there’s a ton of resources already about procedural animation, so I’m going to keep this pretty high level. Okay let’s go! I've grouped the setup into 3 main steps, with some smaller details between.Step 1) Rig the legs with IK so the feet stay still when the body moves. I use Unity’s Animation Rigging package for rig constraints. It has some standard constraints that will be enough for most situations, but you can make custom ones if needed. Ducks always look so squishy to me and I wanted mine to reflect that. So the rig doesn’t follow proper anatomy and many bones are separated so they can move independently. Each leg is just the foot and a single bone that morphs the body to imply a leg. I can’t go over the whole rig, but I'll point out two important constraints I made. One adds rotation to the body based on the separation of the feet for some easy wiggle action. The other bends the toes at a secondary joint when the first has too extreme of an angle. Step 2) Make a script that can perform a step given a target position and rotation. It should move the foot on a curve from its current pose to the new pose. My duck’s feet have a few other features. I can change the speed of the step. Also the foot is prevented from going too far from the body. And when not stepping, if the body gets too far away, the foot clears its target and tucks in at max speed. Step 3) Find each foot’s “preferred” pose relative to the body, usually using a raycast down to the ground from some point on the body. When the distance or angle is big enough between the foot and its preferred pose, tell it to step. You can improve it by limiting the number of feet that are allowed to move at once, and step the foot that is farthest from its target. At this point you can move the body with scripts or whatever and it looks pretty good! I just have a few more details for some extra realism. The duck’s body is a physics object and I move it only by applying forces. This allows it to push and be pushed by other physics objects. Joystick input applies horizontal forces, and a vertical force gets applied to keep it hovering above the ground. The height it’s trying to hover at is based on the successful raycasts from the leg controller, and only applies if at least one foot is grounded. That way it can fall off ledges or trip if it can’t find footing. To keep the body upright, I have a configurable joint with a slerp drive and configured-in-worldspace ticked. Then I can just set the joint's Target Rotation on the joint in a script to make it turn with physics. Back to the feet, I mentioned before that they will tuck it their target is too far away. So I added a rule that a tucked foot will be told to step as soon as a new target pose is found, regardless of the other leg. This allows both legs to extend when landing from a fall. Finally, I change the speed of the steps based on the body’s linear or angular speed. Also I don’t just raycast from the body’s current pose, but use its velocity to look ahead and cast from where it will be in one step’s worth of time. And I think that covers the majority of the leg setup at the moment! I’m not sure if that made any sense at all, but I hope the gifs were entertaining at least 😅 I have a lot more planned, and I'm looking forward to sharing as I go!If you made it this far thank you so much for reading! And if you learned something new from this or maybe got inspired to take a quack🦆at some procedural movement, I’d love to hear!

Unroll Another Tweet

Use Our Twitter Bot to Unroll a Thread

  1. 1 Give us a follow on Twitter. follow us
  2. 2 Drop a comment, mentioning us @unrollnow on the thread you want to Unroll.
  3. 3Wait For Some Time, We will reply to your comment with Unroll Link.