How to shoot a bullet on a moving object,How to shoot a bullet from an object moving in the direction of motion

Hi all,
I want to shoot a bullet from an object moving in the direction of motion.
I wrote this script but the bullet don’t match the direction of movement of the object,Hi all,
I want to shoot a bullet from an object moving in the direction of motion.
I wrote this script but the bullet don’t match the direction of movement of the object.

    if (Input.GetKeyDown("space"))
    {
        Instantiate(bullet, new Vector3(gameObject.transform.position.x, 3, gameObject.transform.position.z), Quaternion.identity);
    }

you need gameObject.transform, just transform. You do need the rotation of the player… like how do you move your player forward? just do the same thing with the bullets but faster.