原料:一個(gè)被動(dòng)作綁定過(guò)骨骼的毛筆
原理:原理其實(shí)很簡(jiǎn)單,通過(guò)判斷毛筆移動(dòng)的方向卵惦,對(duì)筆頭的骨骼做一個(gè)相反方向的運(yùn)動(dòng),骨骼從下到上的運(yùn)動(dòng)量呈衰減狀態(tài)
public class TestMaobi : MonoBehaviour {
public Transform[] childBone;//筆頭的骨骼節(jié)點(diǎn)
public Vector3[] BoneLocalPos;
private Vector3 lastPostion;
private Vector3 nowPostion;
// Use this for initialization
void Start () {
BoneLocalPos = new Vector3[childBone.Length];
for (int i=0;i<BoneLocalPos.Length;i++)
{
BoneLocalPos[i] = childBone[i].localPosition;
}
lastPostion = this.transform.position;
nowPostion = this.transform.position;
}
public Vector3 m_MoveDir;
void LateUpdate()
{
lastPostion = nowPostion;
nowPostion = this.transform.position;
Vector3 moveDir = nowPostion - lastPostion;
m_MoveDir = moveDir.normalized;
if (!moveDir.Equals(Vector3.zero))
{
for (int i = 0; i < childBone.Length; i++)
{
Vector3 _moveDir = childBone[i].InverseTransformDirection(m_MoveDir);
childBone[i].localPosition = Vector3.Lerp(childBone[i].localPosition, BoneLocalPos[i] - new Vector3(Mathf.Clamp(_moveDir.x * i * Time.deltaTime * 30f, -0.0015f * i, 0.0015f * i), 0, Mathf.Clamp(_moveDir.z * i * Time.deltaTime * 30f, -0.0015f * i, 0.0015f * i)), Time.deltaTime * 10f);
}
}
}
}