Boxcast/Raycast Orientation

I started with the API Scripting reference’s Physics.BoxCast example code:
[Unity - Scripting API: Physics.BoxCast]
…and it works great… until the game object rotates, see:

I know I’ve been something crazy for other people to try to look at, but here are some snippits of one ray/boxcast:

        public float w = 9f;
        public float h = 34.5f;
        public float d = 24;
        bool m_HitDetectFORE;
        RaycastHit m_HitFORE;
        float meausure_MaxDistance = 144f;
    
    void FixedUpdate() {
            
            m_HitDetectFORE = Physics.BoxCast((transform.position + new Vector3(w / 2, h / 2, -d)), new Vector3(w / 2, h / 2, 1f), -transform.forward, out m_HitFORE, transform.rotation, meausure_MaxDistance);
            if (m_HitDetectFORE) { Debug.Log("FORE Hit : " + m_HitFORE.collider.name); }
    }
    
    void OnDrawGizmos() {
            Gizmos.color = Color.cyan;
    if (m_HitDetectFORE) {
                     Gizmos.DrawRay((transform.position + new Vector3(w / 2, h / 2, -d)), -transform.forward * m_HitFORE.distance);
                Gizmos.DrawWireCube((transform.position + new Vector3(w / 2, h / 2, -d)) + -transform.forward * m_HitFORE.distance, new Vector3(w, h, 1f));
            } else {
                     Gizmos.DrawRay((transform.position + new Vector3(w / 2, h / 2, -d)), -transform.forward * meausure_MaxDistance);
                Gizmos.DrawWireCube((transform.position + new Vector3(w / 2, h / 2, -d)) + -transform.forward * meausure_MaxDistance, new Vector3(w, h, 1f));
            }

I have benefited enormously from reading the wealth of existing answers on this forum,
but I can’t piece together what’s going on with this contraption. Thanks!

Adding a simple Vector to the transform.position will always add a offset in world space, no matter the orientation of your cube. If you want let’s say an offset into the cubes forward direction, use transfrom.position + transform.forward * offset

Thanks @hexagonius ,
I ended up just keeping everything pivoting off the center, and adjusting the distance. It didn’t want to read “0” distance, so I made it report “Boxcast distance from center minus half the geometry dimensions.”

How do I orientate the wirecube gizmos?