Procedurally Animated 3D Models
Inspiration And References:
I was inspired to do this project when a friend showed me a video about it from the youtuber Codeer. Then I started doing research with my friend, Maxens Haramburu, to understand how this kind of animation works and start writing scripts to model this type of behavior ourselves.
Here are some of our research references.
The Project:
(Here I show a series of gifs about the steps we took to achieve procedurally animating a 3D model)
(At the bottom of the page you can find a paragraph of the problems we found and the solutions we came up with)
Github Repository Link
Step 1: Locking the feet to the ground at a specific target
Step 2: Setting a step target
2.1: Checking the distance between the feet target and step target
Step 3: Move feet to the step target when the distance is too big
Step 4: Smooth the feet movement
Step 5: Alternate legs movement
Step 6: Reposition body height (2 gifs for visual comprehension on the importance of this step)
With no reposition:
With body height repositioning:
Step 7: Reorientating the body when not on a flat surface
Step 8: Applying same principles on a new model with multiple legs
About the process:
The project went smoothly for most of the parts, but we did have some problems for which the solutions took a considerate amount of time to find.
Steps 1 through 4 were fairly simple, with no major complications in the understanding how to do it and applying it.
Most of the complications were found in steps 5 through 7, and step 8 was fairly simple once we had all the solutions.
Problems and solutions:
Step 5:
The problem was about the logic used in how each leg will act independently of dependently of each other. We had to have a leg move when the other leg isn't moving, or in the case of the spider, have opposite legs move at the same time.
Our solution was to have each leg keep track of the legs adjacent and opposite to them.
When a leg is about to perform a step movement, it will check if the leg adjacent to it is already moving or not. If the adjacent leg is moving it will wait until it ends moving to perform a step, if it was not moving it will immediately perform a step.
In the case of the spider, only knowing the state of the adjacent leg will not be enough. We want to know about the opposite legs too. What we came up with is that we made one of the legs control the state of the opposite leg to it, so when that leg takes a step, it will call a function to make the opposite leg take a step at the same time.
Step 6:
The problem was that the models wouldn't reposition their body height when walking on an uneven surface.
The solution we came up with was to calculate the legs average position and then add the averaged "y" position to the body "y" position.
Step 7:
The problem was that the body orientation wouldn't adapt to that of the surface their stepping on. By far the hardest problem to solve.
After trying different approaches, our solution to it was to calculate an averaged normal by adding up the normal of each leg and dividing the addition by the total number of legs, then apply the rotation of this averaged normal to the rotation of the body. The way we got the rotation of the averaged normal was by applying it to the up direction of an empty GameObject, then getting the rotation of said object, which was easier than having to manually calculate different angles that don't take into account 3D quaternion rotation properties.
*To note: These models are not ours, the spider was taken from a package at the Unity Asset Store, and the walker comes from a Unity Prototyping Series document.
Thank you for reading!