I’m trying to determine the distance from my raycast hit from the player, but only in the vertical direction. I’ve almost got it, but my RaycastHit.point.y always returns 0 even when it’s way up over 80 in reality. The reference says that RaycastHit.point.y should return in worldspace, but it seems like its returning in local space.
var wayPointPrefab : GameObject;
var cube : GameObject;
private var player : GameObject;
function Awake(){
player = GameObject.Find("Player");
}
function Update(){
zoomer = GetComponent(cameraZoomer);
mouseLocked = zoomer.mouseLocked;
if(Input.GetButton ("Fire1")!mouseLocked){
//Debug.Log("Button Clicked");
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
//Debug.Log("Ray Fired");
verticalDistance = player.transform.position.y - hit.point.y;
print(verticalDistance);
print("hitpoint y: " + hit.point.y);
if(Physics.Raycast(ray, hit, 10000))
{
/*if(cube){
Destroy(cube.gameObject);
}*/
//Debug.Log("hit point:"+hit.point);
//hitPoint=Vector3(hit.point.x,hit.point.y,0);
if(!cube){
cube = Instantiate(wayPointPrefab);
}
//cube = wayPointPrefab;
cube.transform.position = Vector3(hit.point.x,hit.point.y+1,hit.point.z);
playerNewTarget = Vector3(hit.point.x,hit.point.y+1,hit.point.z);
//print("go!");
player.SendMessage("moveActive",playerNewTarget);
}
}
}
Can anyone tell what I’m doing wrong?