Weird Rayscast-Distances

Hello,

Based on some tutorial-material i made a small terrain to play arround and imported a first-person-controller.
Now I’ve added an empty GameObject as a child to the Main Camera and added this script to determine the distance to certain objects:

using UnityEngine;
using System.Collections;

public class MeleeSystem : MonoBehaviour {
	public int Damage = 10;
	public float Distance = 0;
	public float MaxDistance = 1.5f;
	public Axe Weapon;
	public AudioClip hitsound;
	// Use this for initialization
	void Start () {
		setMaxDistance (Weapon);
	}
	
	// Update is called once per frame
	void Update () {
	if (Input.GetButtonDown ("Fire1")) 
		{
			RaycastHit hitRayCast;
			Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward),Color.blue, 30);
			if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hitRayCast, Mathf.Infinity))
				{
				Distance = hitRayCast.distance;
				if(Distance <= MaxDistance)
					{
						audio.PlayOneShot(hitsound);
						Weapon.animation.Play("AxeHit");
					}
				}
		}
	}

	void setMaxDistance(Axe tool)
	{
		MaxDistance = tool.Length + 1.5f;
	}

	void OnGUI()
	{
		GUI.Box(new Rect(Screen.width/2,Screen.height/2, 10, 10), "");
	}
}

As I said, I’m just starting to play arround… Right now I have the problem, that the values don’t make sense to me.
When i look down straight, I get 0.12 as distance, but when I highen up the angle just a little I get 5.82…
I’ve added an screenshoot to ilustrate my problem.

26018-unbenannt.png

Can someone please explain this to me?
Google didn’t help so far.

Greetings

I finally got it figured out…
Since the camera doesn’t follow an 90° angle (it can only handle 60°) the distance in this case is calculated by the height of the FPS-controller + the height of the Main Camera-Component. In my case the FPS-controller had a height of 1,05 and the Main Camera-component a height of 0,90 which made a total height of 1,95 units.
Therefore the distance became a hypthenuse of a triangle.
(I leave this here, so future newbies like me can figure it out more specificly, because this approach only gave the rough values.)