Accurate Projectile Leading for AI [3D]

Here are two versions of projectile leading I found, one works somewhat but only if the player is at the correct distance and velocity. It’s very unadaptable in that sense.

        Vector3 targetRot = Player.transform.position + new Vector3(playerVelocity.x, playerVelocity.y * 0f,playerVelocity.z) * (predictRotation) - transform.position;
        Quaternion toRotation = Quaternion.LookRotation(targetRot);
        transform.rotation = Quaternion.Lerp(transform.rotation, toRotation,RotSpeed * Time.fixedDeltaTime);

The other one comes from unity wiki (This is not working me at all and not sure why but the AI just rotates sideways and stays there. The player’s velocity and transform posiition is being updated as well so I’m not sure what’s happening).

https://wiki.unity3d.com/index.php/Calculating_Lead_For_Projectiles

Any help with this is appreciated.

Here are the variables which I think belongs in the script. To make things less complicated the player will have a static movespeed of 5f.

-Distance float from enemy to player
-Projectile Speed

I figured out how to make the call to the function but still it isn’t working in a 3D space. The only time the enemy is rotating towards the player is when the player is running away from the enemy.

Calculating player’s velocity w/ Kinematic Rigidbody (found from a reddit thread)

        public void FixedUpdate()
        {
            playerVelocity = (transform.position - pos) / Time.deltaTime;
            pos = transform.position;
        }

The enemies rotation as a placeholder which is constantly shooting projectiles forward. The enemy is stationary for now.

 private void EnemyRotation()
 {  
        Vector3 targetPosition = FirstOrderIntercept(transform.position,rb.velocity,projectileSpeed,enemyTarget.transform.position,scr_Controller.playerVelocity);
        transform.rotation = Quaternion.LookRotation(targetPosition);
         AutoFire();
  }