Hitting Moving Target Debugging Help

I have been trying to make a script for my tower defense game that will always aim ahead on a moving target so it will always hit when in range. It works fine on slow speeds or at certain distances but if I add more speed to the enemies or two dimensional motion, it misses most of the time. I can’t for the life of me figure out what about this script is missing so much. I’ve followed a few different posts but this version is most closely adapted from this link: physics - Find meeting point of 2 objects in 2D, knowing (constant) speed and slope - Game Development Stack Exchange

Here is the code for the gun:

    public GameObject turret;
    public GameObject target;
    public GameObject bullet;
    public float ReloadTime = 3f;
    public float LastReload = 0f;

    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(turret.transform.position, target.transform.position) < 10f && LastReload <= 0)
        {
            Vector3 aimAt = getAimAt();
            LastReload = ReloadTime;
            var newBullet = Instantiate(bullet, turret.transform.position, Quaternion.identity);
            newBullet.transform.LookAt(aimAt);
        }

        if (LastReload > 0)
        {
            LastReload = LastReload - Time.deltaTime;
        }
    }

    Vector3 getAimAt()
    {
        float distance = Vector3.Distance(turret.transform.position , target.transform.position);

        float dx = target.transform.position.x - turret.transform.position.x;
        float dz = target.transform.position.z - turret.transform.position.z;


        float a = (target.GetComponent<Rigidbody>().velocity.x* target.GetComponent<Rigidbody>().velocity.x) + (target.GetComponent<Rigidbody>().velocity.z * target.GetComponent<Rigidbody>().velocity.z) - (.2f * .2f);
        float b = 2 * (target.GetComponent<Rigidbody>().velocity.x * (dx) + target.GetComponent<Rigidbody>().velocity.y * (dz));
        float c = ((target.transform.position.x - turret.transform.position.x) * (target.transform.position.x - turret.transform.position.x)) + ((dz) * (target.transform.position.z - turret.transform.position.z));

        float q = b * b - 4 * a * c;
        if (q < 0) return Vector3.zero;

        float t = ((a < 0 ? -1 : 1)) * ((float)Math.Sqrt(q) - b) / (2 * a);
        Debug.Log(t);

        dx += t * target.GetComponent<Rigidbody>().velocity.x;
        dz += t * target.GetComponent<Rigidbody>().velocity.z;

        Vector3 aimPoint = new Vector3(dx, 0f, dz);
        return aimPoint;
    }

and here is the code for the bullet:


    private float speed = .2f;
    private float lifetime = 3;

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.forward * speed);
        lifetime = lifetime - Time.deltaTime;

        if ( lifetime < 0)
        {
            Destroy(gameObject);
        }

    }

Any help would be much appreciated!