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!