在进行unity开发时,使用character control组建的实例,人物平滑的转向,然后朝着正前方移动。
这里实现三个效果,鼠标点击物体向正前方移动、awsd控制朝向、物体始终朝向目标。
1)鼠标点击目标移动
if (Input.GetMouseButton (0))
{
transform.Translate (Vector3.forward * Time.deltaTime * moveSpeed, Space.Self);
}
2)awsd控制朝向
//获取控制的方向, 上下左右,
float KeyVertical = Input.GetAxis ("Vertical");
float KeyHorizontal = Input.GetAxis ("Horizontal");
Vector3 newDir = new Vector3 (KeyHorizontal, 0, KeyVertical).normalized;
transform.forward = Vector3.Le