Firing a shell from a tank which rotates

So I rotate a tank turret and want the shell to fire from an origin position that is just in front in the barrell. But because the barrell keeps rotating with the turret, I’m unable to obtain an origin position that is relative to the tank’s rotation if that makes sense.


  private void Fire ()
            // Set the fired flag so only Fire is only called once.
            m_Fired = true;
            //set origin position of shell to be just infront of turret barrell
            Vector3 shellOrigin = new Vector3(tankTurretTransform.position.x+1, tankTurretTransform.position.y, tankTurret.transform.position.z+1);
          //  m_FireTransform.position = new Vector3(tankTurretTransform.forward.x, tankTurretTransform.forward.y, tankTurretTransform.forward.z+0.3f);
            // Create an instance of the shell and store a reference to it's rigidbody.
            Rigidbody shellInstance =
                Instantiate (m_Shell, shellOrigin, tankTurretTransform.rotation) as Rigidbody;

            // Set the shell's velocity to the launch force in the fire position's forward direction.
            shellInstance.velocity = m_CurrentLaunchForce * tankTurretTransform.forward; 

            // Change the clip to the firing clip and play it.
            m_ShootingAudio.clip = m_FireClip;
            m_ShootingAudio.Play ();
            ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo>();
            // Reset the launch force.  This is a precaution in case of missing button events.
            m_CurrentLaunchForce = m_MinLaunchForce;

With my code, the origin position of the shell does not make sense as I rotate the turret, and I end up blowing up my own tank.

Solved. There is a GameObject called FireTransform in the hierarchy that can be adjusted for this.

Try transform.localPosition instead of transform.position.