Unity Camera 自旋及沿自身坐标系方向移动(一)

void Update () {
  float h = Input.GetAxis("Horizontal");
  float v = Input.GetAxis("Vertical");

  if (Input.GetKey(KeyCode.J))
  {
    transform.Rotate(-Vector3.up * Time.deltaTime * 50f, Space.World);
  }

  if (h != 0 || v != 0)
  {
    Vector3 targetOffset = new Vector3(h, 0, v);
    float y = transform.rotation.eulerAngles.y;
    Vector3 targetDirection = Quaternion.Euler(0, y, 0) * targetOffset;
    transform.Translate(targetDirection * Time.deltaTime * 50, Space.World);
  }
}

  

posted on 2018-07-10 15:01  潭水画鹤舞  阅读(190)  评论(0)    收藏  举报

导航