Weapon not firing straight.
Bullet moving script (in a FixedUpdate function):
transform.Translate(transform.forward* bulletSpeed * Time.fixedDeltaTime, Space.Self);
Bullet spawning script:
Instantiate(bulletPrefab, spawnPoint.transform.position, spawnPoint.transform.rotation);
If I'm facing one direction it fires fine but as I turn the bullets fire in a completely different direction. The spawn point is a child of the player so it is rotating with the player.
Any help?
Answer by Sn1p3r5 · Mar 25, 2017 at 04:10 PM
Try changing this:
transform.Translate(transform.forward* bulletSpeed * Time.fixedDeltaTime, Space.Self);
to this:
transform.Translate(transform.forward* bulletSpeed * Time.fixedDeltaTime, Space.World);
When you are supplying transform.forward in translate, you are dealing with the object's direction with respect to world coordinate (Space.world). Therefore, using Space.Self as the relative space is causing inconsistency.
Your answer
![](https://koobas.hobune.stream/wayback/20220612103335im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Bullet Not Working 1 Answer
Teleporting To Projectile Location 1 Answer
Instantiate GameObject with Velocity 1 Answer
Score counter not working properly. 1 Answer
Bullet to Mouse Position? 1 Answer