Raycast script not working close to the object

Made a simple raycast script, but it doesn’t work when I’m close to the object. I have to take a couple steps back. Why might this be?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Laser : MonoBehaviour
{
    public Camera PlayerCamera;


    void Update()
    {
        RaycastHit hit;
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (Physics.Raycast(transform.position, transform.forward, out hit, 4.0F) && hit.transform.tag == "cube")
            {
                hit.transform.parent = PlayerCamera.transform;
                hit.transform.GetComponent<Rigidbody>().useGravity = false;
                hit.transform.position = new Vector3(0, 0, 0);
            }
            else
            {
                Debug.Log("you arent hitting anything");
            }
        }
    }
}

Raycasts only detect colliders if they start on the outside of the collider. LineCasts however can both start and end inside a collider, and it will still detect the collider. just be aware that linecasts are a bit more expensive to use than raycasts.