- Home /
Want ray cast to be true when intersecting any object
I have this ray
Physics.Raycast (transform.position, dwn, 5)
in an if statement which is true when I am close to the terrain at the bottom. [ so basically it only seems to respond to terrain, I have print statements at the bottom to make sure ]
How can I get it to be true when I am above ANY object!
??
Thank you = )
do the objects you want to RayCastHit have colliders and are on layers that are set to interact in Physics.$$anonymous$$atrix?
Add: https://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
You must declare a hit
RaycastHit hit; Physics.Raycast(from, to, hit) Debug.Log(hit.collider.gameObject);
the objects are irregularly shaped ( trees ) ! How do I get a collidor on that? Also what do you mean PHysics.matrix? I just set collidor to cube and it works but I don't want it to work with a cube. $$anonymous$$ust be the trees shape!
The irregular shapes does not matter, as long as their colliders are according to their meshes, because the raycast will collide with the first collider it hits!
Are these project Trees (shown in the Project Hierarchy) with colliders (mesh, box, etc) or are these Terrain trees painted on via brush or via $$anonymous$$ass Placed?
Answer by getyour411 · Mar 06, 2014 at 02:32 AM
I haven't seen a reply re: terrain or placed tree. If it's a placed tree, you can work through Mulldor's suggestions. If it's a terrain tree (or you plan to make them terrain trees) you'll need to consider a few additional things. Details here
http://answers.unity3d.com/questions/650308/how-do-i-interact-with-terrain-trees.html