I’ve been working on an animation controller using mecanim and a generic rig for a mech chassis. Currently I have a walk/run animation, and a turn left/right animation. I’ve set up my code so that the foot delta from the animations transforms my object forward and rotates the mech. However, I can’t seem to resolve foot sliding when the mech enters a turn. I’ve been at this for a couple days and struggling to understand why my feet keep sliding. I figured out that when in a turn, the outer leg moves faster than the inner leg to cover the same distance, but beyond that I am lost. Would anyone have any suggestions at to what could be the issue?
The gif below demonstrates the problem when turning…
actualsoulfulbillygoat
The gif below shows moving straight with no foot sliding…
heavenlytepidarchaeocete
private void Animate()
{
if (m_FootIndex == 0) //Left Foot
{
m_CurrentFootPosition = new Vector3(m_FootLeft.localPosition.x, 0, m_FootLeft.localPosition.z);
}
else if (m_FootIndex == 1) //Right Foot
{
m_CurrentFootPosition = new Vector3(m_FootRight.localPosition.x, 0, m_FootRight.localPosition.z);
}
//Calculate delta and apply translation
float footDeltaZ = m_LastFootPosition.z - m_CurrentFootPosition.z;
//m_De & m_De2 are test floats for turning. When turning, outer leg is moving faster than the inner
if (m_FootIndex == 0) { transform.position += transform.forward * footDeltaZ * m_De; }
else { transform.position += transform.forward * footDeltaZ * m_De2; }
m_LastFootPosition = m_CurrentFootPosition;
}
/// <summary>
/// Animation clip event called when either left or right foot is planted
/// </summary>
/// <param name="p_FootIndex"></param>
private void On_FootPlanted(int p_FootIndex)
{
//Set the foot index and grab the local position of the current foot
m_FootIndex = p_FootIndex;
if (m_FootIndex == 0)
{
m_LastFootPosition = new Vector3(m_FootLeft.localPosition.x, 0, m_FootLeft.localPosition.z);
}
else
{
m_LastFootPosition = new Vector3(m_FootRight.localPosition.x, 0, m_FootRight.localPosition.z);
}
}
I’ve also attached videos of the animation cycles themselves for further info
unsteadywarpedarkshell
flimsyexcitableallosaurus
Unless you get a little fancy with IK pinning, this is a normal thing to see. The body as a whole has one position and one rotation, and all bones are just offsets from that.
So I started build a rudimentary IK rig for my game as you can see with those green bones. I would then have to “pin” the planted foot on the ground by moving it the inverse direction of where the animation wants to take it right?
Did you try to rotate around the foot. it would need scripting. Using RotateAround or Orbit-around or by teleporting an object to the grounded foot position reparenting the entire object and rotating the foot anchor.
No I haven’t but I get what you are saying. However, if I were to do that, would I just use my “walk straight animation” in that case? My turn animation rotates the root node of the object.
It would probably obsolete the turn animation entirely if it effected the root rotation, think about how a dinosaur or bird runs they lean and perform a wide turning circle with tiny and gradual rotations altering the forward.
i am not sure of it entirely I have never done this myself.
Basic IK is “how can I get this foot position to be on the ground during this frame?” IK pinning is “okay, until I tell you to move the foot off the ground, how can I get this foot position and rotation to be on the ground at the same place for every frame?”
Your robot joints seem very constrained, like they can only move in the YZ plane. You will need a little more leeway to allow the hip and ankle to bend to the side a bit, in order to work with IK pinning in a turn.
Pinning was the solution, foot sliding when turning is no longer the issue. What I did was grab the hit point of the foot when the animation clip event “On_FootPlanted” fired, and then provide my IK solver that point as the target position. Seems to work well at the moment.