简体   繁体   English

Unity Spawned Object不会向前旋转

[英]Unity Spawned Object doesnt rotate forward

In my Game I shoot Projectiles in the direction where I look... but for example when I shoot to the right the Projectile is straight and dont go forward. 在我的游戏中,我朝着自己看的方向射击弹丸……但是例如,当我向右射击时,弹丸是笔直的,不要向前走。 This is what i use to make them move: 这就是我用来使它们移动的方法:

GetComponent<Rigidbody>().AddForce(Camera.main.transform.forward * projectileSpeed);

射弹射击 射击弹丸但不向前

不要朝我看的方向旋转

Ok before you throw, you need to orient it just like the camera: 好的,在抛出之前,您需要像照相机一样调整它的方向:

transform.rotation = Camera.main.transform.rotation;
GetComponent<Rigidbody>().AddForce(Camera.main.transform.forward * projectileSpeed);

If the object is along the Z axis this should work. 如果对象沿Z轴,则该对象将起作用。 Otherwise we'll need to add some rotation to it. 否则,我们需要对其进行一些旋转。

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

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