原料:一个被动作绑定过骨骼的毛笔
原理:原理其实很简单,通过判断毛笔移动的方向,对笔头的骨骼做一个相反方向的运动,骨骼从下到上的运动量呈衰减状态
public class TestMaobi : MonoBehaviour {
public Transform[] childBone;//笔头的骨骼节点
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);
}
}
}
}