Upon shooting, Raycast target moves infinitely

Hello, I’m working on a Metroidvania style platformer and can’t seem to figure out getting the shooting aspect to work properly.

I’m using a Raycast to launch forward upon shooting to check if I can hit something, but the object that I’m using as the direction to shoot in (which I’ve called the endpoint) moves in various speeds in a set direction along the X axis when I point it either way. When I’m moving it is in the correct position, but sometimes it doesn’t move to point in the opposite direction, other times it automatically moves to the other side when I don’t want it to and others it just disappears.

When shooting the Raycast line does hit and end at the objects that I want it to, but I don’t think I should leave the endpoint moving forward forever.

		Vector2 input = new Vector2 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"));
		Vector2 endPosition = new Vector2(endPoint.position.x, endPoint.position.y);

		if (input.y == 0 && input.x == 0) {
			endPoint.transform.localPosition = new Vector2 (endPosition.x, 0);
		if (input.y > 0.25) {
			endPoint.transform.localPosition = new Vector2 (0, 1);
		if (input.x > 0.25) {
			endPoint.transform.localPosition = new Vector2 (2, 0);
		if (input.x < -0.25) {
			endPoint.transform.localPosition = new Vector2 (-2, 0);

Link to demonstration if I’m not explaining it correctly.

I of course want to just leave the endpoint’s X axis position at 2 or -2 from the center of my character based on what I had it at last. Pointing upward seems to work fine, where the endpoint moves to where I want it to when pushing up. But it’s the horizontal pointing which is all messed up. Any ideas? Please forgive me if this is a simple fix, this is my first time programming a game.

Thanks in advance!

Well I’m not too sure what I did but I ended up fixing it. I think I maybe when I had it shooting forever I also had it set to move while shooting. Either way, I have shooting working now. Case closed!