Raycast won't hit Collider

I trying to build a point and click system where the point i click will become destination point for the NavMeshAgent. Here is the code i am using:

if (Input.GetKey (KeyCode.Mouse0)) {
						ray = characterCamera.ViewportPointToRay (Input.mousePosition);
						didHit=Physics.Raycast (ray, out hit);
						Debug.Log (didHit.ToString ());
						Debug.DrawRay (ray.origin,ray.direction,Color.red,30f);
						if (didHit) {
							rayHitPosition=hit.point;
							currentMarker=Instantiate (Marker,rayHitPosition,Quaternion.Euler (Vector3.zero));
}

My floor is a basic plane with a plane collider. This code always shows didHit false even if i am obviously pressing on the plane. Even Debug.DrawRay doesn’t draw anything even though debugging shows ray variable does contain a valid ray. characterCamera is my main camera.

The viewport space is the normalized screen space, meaning that the bottom left of the screen has the coordinates (0,0) and the top right has (1,1). The mousePosition uses screen space which is from (0,0) to (Screen.width, Screen.height).

Try using ScreenPointToRay instead:

ray = characterCamera.ScreenPointToRay(Input.mousePosition);