首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Quaternion.Euler(Obj.Transport.rotation.x、Obj.Transport.rotation.y、Obj.Transport.rotation.z)和Obj.transform.rotation有什么区别吗?

Quaternion.Euler(Obj.Transport.rotation.x、Obj.Transport.rotation.y、Obj.Transport.rotation.z)和Obj.transform.rotation有什么区别吗?
EN

Stack Overflow用户
提问于 2022-06-30 20:53:52
回答 1查看 21关注 0票数 0

我试着设计出一种武器,它发射的子弹比它跟踪鼠标时的角度要低几度或更多。我用这段代码发射了一个弹丸:

代码语言:javascript
复制
GameObject bullet = Instantiate(bulletPrefab, FirePoint.transform.position,Gun.transform.rotation);
bullet.GetComponent<Rigidbody2D>().AddForce(bullet.transform.up * -2000);

效果很好。当我试图改变子弹的轨迹时,我把它改成了这个。

代码语言:javascript
复制
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)有什么区别吗?这个问题有什么解决办法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-06-30 21:22:06

当你得到旋转时,你得到了四元数的x分量(x,y,z,w),在你的例子中,你需要Euler Angles,所以得到旋转。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72821903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档