Instantiated object following player movement issue

Hi, so I have a beam that stretches out from top to bottom of my screen. I want to have follow my player around when i activate it. And so after doing some research, a lot of people suggested i create it as a child. This is the code I used:

player = (GameObject.Find(“ShotSpawn”)).transform;
transform.parent = player;

and so, i managed to get the object to follow me as i move my player object around… but everytime I hit other objects with this beam it acts as if it’s my player, and it makes me take damage as if these objects were hitting my player directly, even though it’s only hitting my beam/projectile. So my question is,

is there another way to “clamp” this beam of mine to my character to make it move left and right along with my character?

You can add a script to the beam to have it match the player’s position with an offset;

Vector3 offset;
GameObject player;

void Start(){
offset = new Vector3(0,10,0); // Set this to be however far away you want the beam from the player
player = GameObject.FindGameObjectWithTag ("player");
}

void Update(){
transform.position = player.transform.position + offset;
}

If you are doing a 2d game, just replace Vector3 with Vector2 and remove z-coord.