My 2d spawned bullet prefabs will not fly up, just fall

So this ones weird, my bullets are spawning but when they do they just fall down. IT looks like it has to do with gravity and the rigidbodies, but here is my code anyway:

void Update () {

    handleShooting();
    handleMove();
    handlePause();
  
}

void handlePause()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        cursorLock = !cursorLock;
    }

    if (cursorLock == true)
    {
        Cursor.visible = false;
        Time.timeScale = 1;
    } else
    {
        Cursor.visible = true;
        Time.timeScale = 0;
    }

}

void handleMove()
{
    if (cursorLock == true)
    {
        transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f));

    }
}

void handleShooting()
{
    
    if (canShoot == true)
    {

        shoot();
        StartCoroutine(fire());
    }
    
}

void shoot()
{
    var bulletBullet = (GameObject)Instantiate(
     bullet,
     gun.position,
     gun.rotation);

    bullet.GetComponent<Rigidbody2D>().velocity = bullet.transform.forward * shootVelocity;
    

    Destroy(bulletBullet, 1.2f);

}

any ideas?

Good day.

Can you post a screenshot of the inspector?

Check the Rigidbody compoenent. Unmark the “Use gravity” and mark “is Kinematic”.

Bye

Is the code still the same as what you posted originally? In that case, the problem is that you instantiate a bullet from the prefab ( bulletBullet), but then assign the velocity to the prefab bullet (I wonder how no one has noticed this so far):

void shoot () {
    var bulletBullet = (GameObject)Instantiate(bullet, gun.position, gun.rotation);
    bullet.GetComponent<Rigidbody2D>().velocity = bullet.transform.forward * shootVelocity; // <-- this will not affect your bullet!
}

There might be other problems, but this is the first step to make your bullet fly!

Also, you could store your bullet prefab by its Rigidbody2D, and then instantiate as such, so that you don’t need to get the component. Like this:

[SerializeField] private Rigidbody2D bullet = null; // variable for prefab to be assigned in Editor
...
void shoot () {
    Rigidbody2D bulletInstance = Instantiate(bullet, gun.position, gun.rotation);
    bulletInstance.velocity = bulletInstance.transform.forward * shootVelocity;
}

Since you are working in 2D, you probably don’t want to use transform.forward. That is the Z axis (blue arrow). In 2D, this axis points directly away from the camera. So it probably isn’t doing what you want. And it may look like it’s falling because it has gravity checked? Can’t be sure without an inspector screenshot. But anyways, try using either transform.up or transform.right (depending on which way your bullet sprite faces) instead, and uncheck gravity if it is checked.