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)
? And is there any solution to this problem?
当你得到 rotation.x 你得到四元数 (x,y,z,w) 的 x 分量,在你的情况下你需要欧拉角所以得到 rotation.eulerAngles.x
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.