Getting the distance between 2 children

I have the player as a child of a gameobject. There is a few walls, also all made a child of that game object. The problem is, when I shoot a ray out from the player to one of the walls and ask for the distance, it returns the distance of the player to the center of the parent.

here’s my code

var mask : LayerMask = -1;
var FrontDist = 0.000
function Update () {
	var FrontRay = new Ray (transform.position, transform.forward);
	var hit : RaycastHit;
	if (Physics.Raycast (FrontRay, hit, 100, mask.value)) {
		FrontDist = Vector3.Distance(hit.transform.position, transform.position);
	}
}

I’ve tried using localPostion is every combination. It didn’t return the right distance I tried to refer it too. I’ve got to be doing something wrong or not using something. Any ideas? Thanks for all comments and thoughts in advance!

no:

hit.transform.position

yes:

hit.point

Even easier:
no:

FrontDist = Vector3.Distance(hit.transform.position, transform.position);

yes:

FrontDist = hit.distance;

Good and necessary info, here.

Aww duude! It worked! This is so cool!! Thanks man! Thank you so much!!

You are welcome. All you need to do now is start mashing on the A button, and you’ll be flying. :wink: