15/08/05 00:18:51.11 Wak/H5zk.net
Unity5.1.2でヘリコプターを使ったTPSを作っています。ヘリの操作で旋回や上昇、下降、前進は出来たのですが、
旋回時と前進時に旋回方向、進行方向にヘリを傾けたいと思っているのですが、上手くいきません。
var velocity = new Vector3 (0, 0, 0);
var rb = this.GetComponent<Rigidbody> ();
if (Input.GetAxis ("Vertical") != 0) {
velocity.y = Input.GetAxis("Vertical");
}
if(Input.GetAxis("Horizontal") != 0 && !this.isGrounded){
transform.Rotate(new Vector3(0, rotateSpeed * Time.deltaTime * Input.GetAxis("Horizontal"), 0));
}
if(Input.GetButton("Fire2") && !this.isGrounded){
rb.AddForce(transform.forward *speed,ForceMode.Force);
}
if (Input.GetButton ("Fire2") && (Input.GetAxis ("Vertical") != 0 || Input.GetAxis ("Horizontal") != 0) && !this.isGrounded) {
velocity.y = Input.GetAxis ("Vertical");
transform.Rotate (new Vector3 (0, rotateSpeed * Time.deltaTime * Input.GetAxis ("Horizontal"), 0));
rb.AddForce (transform.forward * speed, ForceMode.Force);
}
this.GetComponent<Rigidbody>().velocity = velocity * 500 * Time.deltaTime;
}
で操作しているのですが、Eulerで傾けようとするとRotateで打ち消されて傾いてくれません。
Y軸方向はGetAxisで、Z軸方向はGetKeyDownで対処しようとしたのですが、それでも上手くいきません。
どなたか旋回しながら、機体を傾ける方法をご存知の方教えてください。