繁体   English   中英

Quaternion.Euler(Obj.transform.rotation.x,Obj.transform.rotation.y,Obj.transform.rotation.z) 和 Obj.transform.rotation 之间有区别吗?

[英]Is there difference between Quaternion.Euler(Obj.transform.rotation.x,Obj.transform.rotation.y,Obj.transform.rotation.z) and Obj.transform.rotation?

我试图设计一种武器,它发射的子弹比它跟随鼠标时的角度少或多几度。 我正在使用此代码发射弹丸:

GameObject bullet = Instantiate(bulletPrefab, FirePoint.transform.position,Gun.transform.rotation);
bullet.GetComponent<Rigidbody2D>().AddForce(bullet.transform.up * -2000);

它运作良好。 然后当我试图改变子弹的轨迹时,我把它改成了这个。

GameObject bullet = Instantiate(bulletPrefab, FirePoint.transform.position,Quaternion.Euler(Gun.transform.rotation.x, Gun.transform.rotation.y, Gun.transform.rotation.z));
bullet.GetComponent<Rigidbody2D>().AddForce(bullet.transform.up * -2000);

即使我将鼠标移动到不同的位置,它也只会向下发射,我不明白为什么。

Gun.transform.rotationQuaternion.Euler(Gun.transform.rotation.x, Gun.transform.rotation.y, Gun.transform.rotation.z)之间有什么区别吗? 这个问题有什么解决办法吗?

当你得到 rotation.x 你得到四元数 (x,y,z,w) 的 x 分量,在你的情况下你需要欧拉角所以得到 rotation.eulerAngles.x

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM