Casting ray forward from transform position

Hey everyone, I’m trying to cast a ray from my player object forward to see if a shot hits something. The problem is that I’ve only found a sample where the ray is casted from the camera’s position. Here’s the code:

void Update () {
   if(Input.GetKey(KeyCode.Escape)){
     Screen.showCursor = true; 
   }
 
   if(Input.GetButtonDown("Fire1")){
     Screen.showCursor = false;
     Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
     RaycastHit hit;
 
     if(Physics.Raycast(ray, out hit)){
       Debug.Log(hit.transform.name); 
       Debug.DrawLine(transform.position, hit.transform.position, Color.red);
     }
   }
 }

But since I’m working on a top-down shooter, I would like to cast the ray from the players transform position (transform.x, transform.y, transform.z+1) into a forward direction. transform.z+1 is there because the ray should start at the gun’s height.
I hope some of you can help me with that.

ok try this one. first make an empty game object and position it where you want your gun then use this code. just reference the function when you want to perform the raycast. dont forget to set the raycast object in the inspector.

public GameObject raycastObject;

void CheckForHit(){

RaycastHit objectHit;

    Vector3 fwd = raycastObject.transform.TransformDirection(Vector3.forward);
    Debug.DrawRay(raycastObject.transform.position, fwd * 50, Color.green);
    if (Physics.Raycast(raycastObject.transform.position, fwd, out objectHit, 50))
    {
//do something if hit object ie
if(objectHit.name=="Enemy"){
Debug.Log("Close to enemy");
}
}
}

this code extends a raycast for 50m so depending on how far you wish it to go you may need to change these figures both on the debug and the actual raycast