I’m currently making a game involving a spinning turret. However, when the turret fires projectiles out of the barrels something occurs, the balls tend to spiral around the turret rather than shoot forward out of the barrels. You can play the current build for yourself.
I think it could be two things causing this:
- Since the projectile emitters I have set up for each turret are parented to a rotating object, the positions at where the projectiles come from are not set properly
- the locations I’ve set the projectiles to instantiate from are the projectile emitters’ local positions relative to their parent object. This could be causing the projectiles to spiral around the parent.
Here’s the code that makes the projectiles instantiate and move forward:
GameObject clone = Instantiate(projectile, turret.localPosition, Quaternion.identity) as GameObject; clone.GetComponent<ProjectileManager>().Activate(); clone.rigidbody.velocity = turret.forward * shotSpeed;
The location is set as local, because the projectile tends to shoot forward in the world space, not local space.
I know I’m missing something simple; I just can’t think of how to solve it. If anyone is able to help me out with this, it would be much appreciated.