today we're implementing a system that
allows our characters to procedurally
walk
welcome to the prototype series a group
of videos in which we'll explore
creating small projects combining
different unity features
this project will extend our previous
procedural boss prototype
and walk you through the setup for a
procedurally animated bipedal character
using the animation rigging package if
you're interested in diving deeper and
learning more
we have a longer training session on our
unity learn website
and you can find a link to it and this
downloadable project
in the video description this video will
walk you through
the creation of our prototype setting up
a rig with the animation rigging package
creating a script to procedurally
animate that rig
and then integrating it into our
original scene
let's get into it
we started by downloading the original
procedural boss prototype
which included assets for a two-legged
robot walker
and the animation rigging package
pre-installed
the model for our robot walker includes
multiple skin meshes and a hierarchy of
transforms
called the rig or skeleton
in the context of 3d animation the skin
mesh plays the role of the skin
or visible surface of the model and the
rig or skeleton
is composed of bones which are objects
which can cause the skin
to follow their movement and the form
much like the bones in the human body
to better visualize this hierarchy in
the scene view we can use the bone
render component
provided by the animation rigging
package
for this we select the first object in
our bone hierarchy
and in the animation rigging menu choose
bone render setup
now we can see all of the bones that
make up the rig for our character
in the scene view normally character
animations are created by setting
keyframes for different poses
of this rig the benefit of the animation
rigging package
is that we can dynamically control the
rig using different constraints
allowing for flexible and dynamic
animations
to create constraints for our rig we
started by selecting our character and
choosing rig setup from the animation
rigging menu
this automatically adds the rig builder
and animator components to our character
as well as a child object named rig1
that will act as a rig layer
organizing our rigs into layers allows
us to stack multiple rigs if we desire
in this case we're using a single rig
any constraints we add to this rig layer
will be automatically added to our rig
constraints in this context can be
thought of as rules
for how our character rig is allowed to
move
an important concept for this type of
animation is that of
inverse kinematics or ik for short
ik allows us to control a chain of bones
for example an arm or a leg
and to cause them to be positioned and
rotated to follow a target
like an apple held at the end of that
arm or in our example here
a foot this allows us to decide where
the end of a chain of joints should be
and have the rig position the other
joints in the chain automatically
for the legs of our walker we use the
two bone ik constraint
which dynamically solves the rotation of
our leg giving a target position for
where we want the foot
to be placed to do this we only needed
to set up the tip transform
and then right click on the component
and choose auto setup from tip transform
in the drop down menu this created a
target and a hint game object that we
used to control the leg
the target object acts as a position of
the foot
and the hand object tells the leg in
what direction to bend
in order to procedurally animate the
legs we created a script which
controlled the position of the target
first we needed to fix the target
position of the foot
to the ground we used a downward ray
cast
to find a position on the terrain for
our foot to go
notice with this done we can move the
body but the feet stay
in place our goal for this character is
to be able to move the body
either from player control or from an ai
script
and to have the feet reposition
themselves procedurally
to do this we needed to find the next
foot placement once the body had moved
we used the new position of the body to
send another raycast down towards the
terrain
if the new position found by the raycast
was over a certain distance from the
previous one
it's time to take a step we used
interpolation to move the target from
our previous position
to our new one and we also used a sine
curve
to add an arc to our step right now the
legs move at the same time
so we offset the initial position of the
feet and added a check
to only animate when one foot is on the
ground
we now have a fully procedurally
animated character ready to be put back
into our scene with a little bit more
code to follow and look at the player
the robot walker is complete
if you want to download and try out this
prototype yourself you can find it via
the link in the description below
there's also a link to the unity learn
website where you can find a longer
training session
showcasing the features used to build
this prototype
thank you so much for watching and i'll
see you in the next one
oh