void Update()
{
MoveLikeWow();
}
private void MoveLikeWow()
{ //这里Horizontal移动在edit-projec setting中更改了设置
var horizontal = Input.GetAxis("HorizontalPlayer2");
var vertical = Input.GetAxis("VerticalPlayer2");
controller.Move(new Vector3(horizontal, 0, vertical) * Time.deltaTime * speed);
if (horizontal != 0 || vertical != 0)
{
Rotating(horizontal, vertical);
}
void Rotating(float horizontal, float vertical)
{
Vector3 targetDir = new Vector3(-1 * vertical, 0, horizontal);
// 传入一个向量值使物体朝向向量方向
Quaternion targetRotation = Quaternion.LookRotation(targetDir, Vector3.up);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, RotateSpeed * Time.deltaTime );
}
}