Bullet not moving towards player

Im making a space shooter game, and I have enemys that shoot at the player, and the bullets are a bullet supposed to move towards the player. It moves NEAR the player, but not actually TOWARDS it. No matter what part of the screen the player is at (think star fox style), the enemy bullets are never actually hitting the player if hes standing still. heres my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyBullet : MonoBehaviour {
    public float speed = 30;
    public GameObject player;
    Vector3 targetLocation;

	// Use this for initialization
	void Start () {
        player = GameObject.FindWithTag("shootPoint");
        Debug.Log(player.gameObject.name); 
        targetLocation = player.transform.position;
        setRotation();

	}
	
	// Update is called once per frame
	void Update () {
        GetComponent<Rigidbody>().velocity = transform.forward * speed;
	}

    void setRotation()
    {
        targetLocation = new Vector3(targetLocation.x, targetLocation.y, player.transform.position.z - 2);
        transform.LookAt(targetLocation);
    }

    IEnumerator setRotationAgain()
    {
        yield return new WaitForSeconds(1f);
        setRotation();
    }
}

Hi,
1.There is no need for GetPlayerWithTag when its public , you can attach gameobject in editor.
2.I can not see any example when placing GetComponent in update is unavoidable , aasign it on start or Awake. Cache it once, or as little as possible. It is a costly venture to the engine.
3. your problem is with this line:

      targetLocation = new Vector3(targetLocation.x, targetLocation.y, player.transform.position.z - 2);//why -2 ??

or maybe int your enemy rigidbody you freeze the x , y position!
I’ve Corrected the code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnCollide : MonoBehaviour {

        public float speed = 2;
        public GameObject player;
        Vector3 targetLocation;
        Rigidbody rb;
        // Use this for initialization
        void Start()
        {
            rb = GetComponent<Rigidbody>();
            targetLocation = player.transform.position;
            transform.LookAt(player.transform);
            rb.velocity = transform.forward * speed;//Velocity Dont need to be in update

        }
        void Update()
        {
        //alternative ways
        // 1.   transform.position += transform.forward * speed * Time.deltaTime;
        // 2.   rb.MovePosition(rb.position + transform.forward * Time.deltaTime);
        //translate ,movetowards ,....

        }

        void setRotation()
            {
                targetLocation = new Vector3(targetLocation.x, targetLocation.y, player.transform.position.z - 2);//why -2 ??
                transform.LookAt(targetLocation);
            }

            IEnumerator setRotationAgain()
            {
                yield return new WaitForSeconds(1f);
                setRotation();
            }
    
}

Also i’ve attached the test project below
[123915-test.zip|123915]

Umm, if it’s like star fox, i’d suggest you don’t move the player forward at all, unless it can be done with input. Instead, add the environment as children to an empty object that will be moved around the player. As for the enemies, in this kind of game, the enemies are usually scripted. Meaning they don’t do random things, so you can plot out their movement around the player’s position, rather than constantly keeping them at a distance of the player. This way, you won’t have to compensate for player movement much either, only the horizontal and vertical movement, but no forward/backward movement.

in case anyones wondering, I tried both versions of the code posted above, neither worked. here is the current code that Im trying to use
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyBullet : MonoBehaviour {
public float speed = 2;
public GameObject player;
Vector3 targetLocation;

// Use this for initialization
void Start () {
    player = GameObject.FindWithTag("shootPoint");
    targetLocation = player.transform.position;
    setRotation();
    GetComponent<Rigidbody>().AddForce(transform.forward * speed, ForceMode.Impulse);

}


void setRotation()
{
    targetLocation = new Vector3(targetLocation.x, targetLocation.y, targetLocation.z);
    transform.LookAt(targetLocation);
}

}
`
when I pause the game I can clearly see that the forward Vector is pointed directly at the player, but the bullet is not moving that way. This truely makes no sense to me, This bug has been persistant for weeks for a very very basic script.