Quantcast
Channel: Questions in topic: "tree"
Viewing all articles
Browse latest Browse all 513

Ray does not hit TreeInstance

$
0
0
Hi Guys, I can't seem to solve a quite simple problem, and it is driving me insane. I can't raycast the tree instances on my terrain. Here are a few screenshots: I draw the ray, in red if it hits something, in blue if it does not hit anything. ![alt text][1] As you can see, the rays hit the terrain, but do not hit the tree. Here is the prefab I am using, it has a capsule collider. ![alt text][2] Code wise here is what is going on: Raycasting: RaycastHit hit; Ray ray = new Ray (mainCamera.transform.position, mainCamera.transform.TransformDirection (Vector3.forward)); if (Physics.Raycast (ray, out hit, 100f)) { Debug.DrawRay (ray.origin, ray.direction * hit.distance, Color.red, 10f); } else { Debug.DrawRay (ray.origin, ray.direction * 200f, Color.blue, 10f); } Creating the tree instance TreeInstance treeInst = new TreeInstance(); treeInst.prototypeIndex = 0; // that gets me my treeprefab treeInst.color = Color.yellow; treeInst.lightmapColor = Color.white; treeInst.widthScale = 1f; treeInst.heightScale = 1f; treeInst.position = position; terrain.AddTreeInstance(treeInst); Can't see what is going wrong, I read about all the posts on the subject. any input is appreciated. If I instanciate a tree from this prefab as a GameObject, then the raycast hits it, the problem is only when the tree is a terrain TreeInstance. Cheers! [1]: /storage/temp/45151-tree-raycast.png [2]: /storage/temp/45152-prefab.png

Viewing all articles
Browse latest Browse all 513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>