我试着设计出一种武器,它发射的子弹比它跟踪鼠标时的角度要低几度或更多。我用这段代码发射了一个弹丸:
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.rotation和Quaternion.Euler(Gun.transform.rotation.x, Gun.transform.rotation.y, Gun.transform.rotation.z)有什么区别吗?这个问题有什么解决办法吗?
发布于 2022-06-30 21:22:06
当你得到旋转时,你得到了四元数的x分量(x,y,z,w),在你的例子中,你需要Euler Angles,所以得到旋转。
https://stackoverflow.com/questions/72821903
复制相似问题