• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Lukamyte · Nov 11, 2013 at 04:00 PM · raycastplane

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...

Comment
gabriele_unity931

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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.

Comment
thedarcsage
StubbornTurtle

People who like this

2 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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.

Comment
DFledermaus
el_santo
thedarcsage
seguso
gabriele_unity931

People who like this

5 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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)

Comment
Lyudmil_P

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lyudmil_P · Nov 21, 2022 at 10:11 PM 0
Share

Genius simple solution.

avatar image

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.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Plane.Raycast vs. Vector3.Projection 2 Answers

Plane.Raycast() out distance incorrect? 1 Answer

raycast hit to relative location on collider? 1 Answer

project view frustrum of camera onto plane as white rectangle 0 Answers

Dragging a Camera along a plane / Where's the error? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges