- Home /
Raycast not detecting planes
I have some randomly generated planes, but, I added a script to make them send a raycast upwards to see if there are any more planes above them. The planes are rotated at Vector3(90, 180, 0).
function Start(){
yield WaitForSeconds(1);
if(Physics.Raycast(transform.position, Vector3.back, 2)){
}else{
Instantiate(so on...)
}
}
I can't find out what's wrong...
Answer by HuskyPanda213 · Nov 11, 2013 at 05:03 PM
Add a cube collider to the plane, this would work better than a mesh collider or whatever you are using.
Answer by Huacanacha · Nov 11, 2013 at 05:24 PM
Planes are single sided non-convex objects. You can only see them on one side (the side the normals are facing) and if you use the default Mesh Collider you can only collide with them on the visible side. To check a collision from 'behind' the plane you need to work around this. Here's a few ways you could do it:
Use a Box Collider with nominal height (0.01 or something depending on the scale of your scene) - this is probably the easiest solution
Use two planes, one facing in each direction
Model a two sided plane yourself and use this instead of the Unity primitive
Note that you may want to use a Quad instead of a Plane primitive for performance reasons. A Quad only has 2 triangles so will be better for rendering, and also physics performance if using a mesh collider.
Answer by DFledermaus · Nov 11, 2013 at 05:06 PM
Do they have colliders? And if so, are they mesh colliders? Unless they are double sided planes if they are facing away from the raycast it may go straight through them.
If the planes are box shaped you may want to give them box colliders instead, that could be faster than mesh colliders anyway.
Answer by DSivtsov · Dec 23, 2021 at 02:42 AM
As a Variant, because a Planes is a single sided, You can change Ray to opposite direction (sent not from start to start + direction, but sent from start + direction , to start)