[英]Is there difference between Quaternion.Euler(Obj.transform.rotation.x,Obj.transform.rotation.y,Obj.transform.rotation.z) and Obj.transform.rotation?
I was trying to design a weapon that fires bullets a few degrees less or more than the angle it makes when following the mouse.我试图设计一种武器,它发射的子弹比它跟随鼠标时的角度少或多几度。 I was using this code to launch a projectile:我正在使用此代码发射弹丸:
GameObject bullet = Instantiate(bulletPrefab, FirePoint.transform.position,Gun.transform.rotation);
bullet.GetComponent<Rigidbody2D>().AddForce(bullet.transform.up * -2000);
It was working well.它运作良好。 Then i changed it into this when i was trying to change trajectory of the bullet.然后当我试图改变子弹的轨迹时,我把它改成了这个。
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);
and it started to fire it only downwards even if i move the mouse to different position and i didnt understand why.即使我将鼠标移动到不同的位置,它也只会向下发射,我不明白为什么。
Is there any difference between Gun.transform.rotation
and Quaternion.Euler(Gun.transform.rotation.x, Gun.transform.rotation.y, Gun.transform.rotation.z)
? Gun.transform.rotation
和Quaternion.Euler(Gun.transform.rotation.x, Gun.transform.rotation.y, Gun.transform.rotation.z)
之间有什么区别吗? And is there any solution to this problem?这个问题有什么解决办法吗?
当你得到 rotation.x 你得到四元数 (x,y,z,w) 的 x 分量,在你的情况下你需要欧拉角所以得到 rotation.eulerAngles.x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.