My bullet keeps following its spawn point after being instantiate. Pls help

Im making a simple top down shooter, but

when I fire and rotate the player, my bullet follows my player rotation.

176679-topdownproject-test-pc-mac-linux-standalone-unity.gif

I think it looks cool but I want it to go in a straigh line. I have no idea how to fix this. Please help.

Here’s my bullet script

public GameObject go;
    private Rigidbody2D bRB;

    public float bulletLifespan;
    public float bulletLifespanReset;
    public float bulletSpeed;


    void Start()
    {
        bRB = GetComponent<Rigidbody2D>();
        go = GameObject.Find("BulletSpawner");

        
    }
    // Update is called once per frame
    void Update()
    {
        BulletMvm();
        Despawn();
    }

    void BulletMvm()
    {

        Transform goTransform = go.GetComponent<Transform>();
        transform.Translate(goTransform.transform.right * bulletSpeed * Time.deltaTime);
        
    }

Here’s where i spawn my bullet

public class BulletSpawner : MonoBehaviour
{
    public GameObject bulletPrefab;
    public Transform spawnPoint;
    //public NormalBullet s_NB;

    public float timer;
    public float fireRate;

    // Update is called once per frame
    void Update()
    {
        ActiveShoot();
    }

    public void ActiveShoot()
    {
        if (timer <= 0.0f)
        {
            Shoot();
            timer = fireRate;
        }
        timer -= Time.deltaTime;
    }

    public void Shoot()
    {
        

        float x = spawnPoint.position.x;
        float y = spawnPoint.position.y;

        Vector2 sP = new Vector2(x, y);
        
        ObjectPooler.Spawn(bulletPrefab, sP, Quaternion.identity);
    }
}

Hi @NicoGm
I think I know how to solve this. Currently the bullet will always go in the direction of the players ‘right’, even after the shot is launched. To not have this problem, add this line to your Start void:

Transform goTransform = go.GetComponent<Transform>();
Vector3 directionOfBullet = go.right;

This will make sure your direction doesn’t change anymore.
In the Update void you should now delete the:

Transform goTransform = go.GetComponent<Transform>();

and you change the transform.Translate to:

transform.Translate(directionOfBullet * bulletSpeed * Time.deltaTime);

*the whole bullet script so you can copy, the above part was for explaining:

 public GameObject go;
     private Rigidbody2D bRB;
 
     public float bulletLifespan;
     public float bulletLifespanReset;
     public float bulletSpeed;
 
 
     void Start()
     {
         bRB = GetComponent<Rigidbody2D>();
         go = GameObject.Find("BulletSpawner");
         //This is to make clear what direction he must go in: V
         Transform goTransform = go.GetComponent<Transform>();
         Vector3 directionOfBullet = go.right;
         
     }
     // Update is called once per frame
     void Update()
     {
         BulletMvm();
         Despawn();
     }
 
     void BulletMvm()
     {
         //This does the movement, but with the good direction.
         transform.Translate(directionOfBullet * bulletSpeed * Time.deltaTime);
         
     }

I hope this solves your problem. Notify me when it works :slight_smile: