Keeping a raycasts origin the same but offsetting the point from which the ray is cast

Im using Raycasting to decide if an object is clickable through tags on objects with colliders, but when Im looking at objects at certain angles, the standard first person controller gets in the way, basically effecting line of sight from itself. I have the Raycast originating from the camera child of the controller because I have the mouse locked to centre screen and the GUI crosshair showing where the mouse is (also changing colour when a “clickable” object is under the crosshair) so the Raycast is pointing in exactly the same direction as the player is looking. Simply moving the camera forward results in the camera ending up behind objects (including walls) when you get too close.

So what I need is a way for the Raycast to start operating in front of where the point of origin of the raycast is, Im afraid if I just move the raycast forward it would not allign to the Crosshair anymore. This is the code Im using.

using UnityEngine;
using System.Collections;

public class Crosshair : MonoBehaviour 
{


	private Color curcol;
	public float interactionDistance = 3f;
	public bool imnear;
	
	void Start () 
	{
		Screen.lockCursor = true;
	}
	
	void OnGUI()

		{
			GUI.color = curcol;
			GUI.Label (new Rect(Screen.width/2,Screen.height/2, 50, 50), "+");
		}
	
	void Update()
	{
		RaycastHit hit;
		Debug.DrawRay(transform.position, transform.forward * interactionDistance);
		if(Physics.Raycast (transform.position, transform.forward, out hit, interactionDistance)) 
		{
			if(hit.collider.tag == "Clickable")
			{
				imnear = true;
			}
			else
			{
				imnear = false;
			}
		}
		else
		{
			imnear =false;
		}
	
		if(imnear == true)
		{
			curcol = Color.green;
		}
		else
		{
			curcol = Color.white;
		}
	}
}

You need to set your character’s colliders on a different physics layer from your rays so the rays you shoot do not collide with them. The Physics.Raycast takes a LayerMask parameter which should accomplish this. See This question for more detailed info on layermasks.

I’m confused about your reference to mouse position. Everything here uses the center of the screen. So you can solve your problem in a variety of ways. The explicit answer you asked for is to do this:

Vector3 v3Pos = transform.position + transform.forward * amount;
if(Physics.Raycast (v3Pos, out hit, interactionDistance)) 

…where ‘amount’ is the amount you want to move the raycast origin forward.

You could also attach this script to an empty child game object in front of the camera. As long as it is in the center of the camera, the crosshair will align.

And @Jamora’s solution will also do the job.