Cannot get raycast to work/created

For some unknown reason i just cant get raycast to actually collide with something or it might not even properly made.

public class Shooting : MonoBehaviour
{
    //Titik awal projectile di tembakkan
    public Transform firePoint;

    //Prefab untuk projectile
    public GameObject bulletPrefab;

    public float bulletForce = 20f;
    public int damage = 20;


    //Method yang akan dipanggil Input System saat tombol kiri mouse ditekan
    public void onShooting(InputAction.CallbackContext context)
    {
        if (context.started)
        {
            Shoot();
        }
    }

    //Method yang dipanggil pada onShooting
    void Shoot()
    {
        //Var bullet untuk projectile yang akan ditembakkan. Mengambil prefab, dan menggunakan data lokasi beserta rotasi dari firePoint
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);

        //Mengambil rigidbody dari projectile yg ditembakkan
        Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();

        //Mengatur arah bergerakknya projectile yang ditembakkan
        rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);

        //LINE ASAL
        RaycastHit2D collision = Physics2D.Raycast(firePoint.position, firePoint.up);
        Debug.DrawRay(firePoint.position, firePoint.up, Color.red);

        Enemy enemy = collision.transform.GetComponent<Enemy>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
    }

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

I even used Debug.DrawRay to see the raycast but it doesnt even show anything (below), its supposed to be in front of the brown tank.

Any help is okay. I kinda need this for my assignment, thank you.

The raycast is probably hitting the tank its originating from. You can prevent this by disabling ‘Queries Start in Colliders’ in the 2D physics settings.

Although you shouldn’t really be ray casting to detect the enemy tank so then you can do damage to it. Instead you can use OnCollisionEnter2D to do the damage

OMG Thank you, that’s exactly it.

And yes, i know i dont really need to use raycast for it. I actually already have alternative using OnCollisionEnter2D, just like what you say. But I kinda have to test the raycast too because the last time I tried using raycast I had this exact problem and I might need raycast this time to make enemies that can follow the player.