1. 方向键方向基于摄像机朝向变化
float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertival = Input.GetAxis ("Vertical");
/*cam是摄像机的transfrom*/ Vector3 camForward = Vector3.Scale(cam.forward, new Vector3(1, 0, 1)).normalized; Vector3 move = (moveVertival * camForward + moveHorizontal * cam.right); rb.AddForce (move * speed);