12-18-2016 05:59 AM
12-19-2016 01:02 AM
12-19-2016 03:15 AM
03-03-2017 03:48 PM
03-07-2017 08:09 AM
lordraider said:
I managed to do it yesterday, just loop through all the joint transforms and lerp just the rotations, not the locations, because the rotation automatically moves your joint in a realistic manner, moving the location from a to b in a straight line makes your finger parts "cringe" 🙂
03-08-2017 09:44 AM
04-08-2017 07:40 PM
using UnityEngine;
using UnityExtensions;
public class LerpAnimation : MonoBehaviour
{
public string RootName;
public GameObject LerpFromPose;
public GameObject LerpToPose;
Transform m_lerpTarget;
Transform m_fromRoot;
Transform m_toRoot;
// Use this for initialization
void Start ()
{
if (null == RootName ||
null == LerpFromPose ||
null == LerpToPose)
{
this.enabled = false;
}
}
public void LerpUpdate(float lerp)
{
if (!this.enabled)
return;
// these skeletons should match up one-for-one, although I don't verify that anywhere
if (null == m_lerpTarget)
{
m_lerpTarget = transform.FindChildAnywhere(RootName);
if (null == m_lerpTarget)
return;
}
if (null == m_fromRoot)
{
m_fromRoot = LerpFromPose.transform.FindChildAnywhere(RootName);
if (null == m_fromRoot)
return;
}
if (null == m_toRoot)
{
m_toRoot = LerpToPose.transform.FindChildAnywhere(RootName);
if (null == m_toRoot)
return;
}
lerp = Mathf.Clamp01(lerp);
Transform cur = m_lerpTarget;
Transform from = m_fromRoot;
Transform to = m_toRoot;
while (true)
{
cur.localRotation = Quaternion.Lerp(from.localRotation, to.localRotation, lerp);
if (0 == cur.childCount)
break;
cur = cur.GetChild(0);
from = from.GetChild(0);
to = to.GetChild(0);
}
}
}