位置跟随是没问题了,可是用了Quaternion.Slerp插值运算,角度跟随还是没有起作用
相机上脚本代码如下:
void Start () {
player = GameObject.FindGameObjectWithTag(Tags.Player).transform;
}
void Update () {
Vector3 targgetPos = player.position + new Vector3(0, 2, -3);
this.transform.position = Vector3.Lerp(transform.position, targgetPos, Speed * Time.deltaTime);
Quaternion targetRotation = Quaternion.LookRotation(player.position - transform.position);
Quaternion.Slerp(transform.rotation, player.rotation, Speed * Time.deltaTime);
}
之后是写主角的控制,在主角的物体上挂了脚本,代码如下:
void Awake()
{
cc = this.GetComponent<CharacterController>();
}
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 targetDir = new Vector3(h, 0, v);
cc.SimpleMove(targetDir * speed);
}
之后相机位置也跟随不了了,当然主角也不能控制移动
跟随这里写错了
Quaternion.Slerp(transform.rotation, targetRotation , Speed * Time.deltaTime);
移动不了的话,可以找到角色身上的animator组件,把apply root motion取消勾选了