Raycasting on Terrain
Hello there For some reason I cant seem to Ray cast to the terrain. I can cast to Objects and even hills but not flat terrain. is my code I hope some can help me.
#pragma strict
var DupObject : GameObject;
var distance : float=5;
var OBJ : Transform;
var Layer : int=1;
function Start () {
}
function Update () {
var foundHit :boolean=false;
var hit : RaycastHit;
if (Input.GetKeyDown(KeyCode.E)){
Instantiate(DupObject, OBJ.transform.position, transform.rotation);
}
if (Input.GetButton("Fire1")){
foundHit= Physics.Raycast(transform.position,transform.forward,hit,Mathf.Infinity,1<<Layer);
}
if(foundHit){
OBJ.transform.position.x = hit.point.x;
//OBJ.transform.position.y = hit.point.y;
OBJ.transform.position.z = hit.point.z;
}
}
PS: I code in javaScript.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612083223im_/https://answers.unity.com/themes/thub/images/avi.jpg)