• 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 /
This question was closed Dec 04, 2016 at 10:25 PM by hexagonius for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by bpears · Feb 27, 2016 at 06:48 PM · physicsraycastraycasthitmesh collider

Raycasting will not hit some imported meshes with mesh colliders?

Using if (Physics.Raycast (ray, out hit, etc, etc) {

and some code, the raycasts are ignoring mesh collider. Tested using a cube in the same position, and it works. Yes I am using appropriate layer for both that I have set up. Makes no sense. Normals of mesh are not reversed because the mesh is shaded with texture correctly. It would be invisible from top if normals were flipped. Makes no sense. Can someone do a simple test? It is an imported non primitive shape. It is terrain shaped.

EDIT: Did a test in a new project/scene. Used imported meshes and it worked, they were pretty basic, a cube, a plane, and a subdivided plane (very low triangles though). Tried importing the original mesh I was working with, which is about 8000 tris, 4500 verts, still does not get hit by the raycast. I am wondering if there is a hidden limit enforced on raycasting topology? Or maybe there is something wrong with the mesh somehow?

After a lot of tests, I believe it is the mesh. I don't understand what could be wrong with it. Especially when it still collides with rigidbodies, and the normals are facing correctly. What all could be wrong with any given mesh that I can look into?

Comment
Add comment · Show 2
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 bpears · Feb 27, 2016 at 07:05 PM 0
Share

using 5.2.3f1 64 bit on windows 10

avatar image roman_sedition · Dec 04, 2016 at 02:53 AM 0
Share

Have you drawn the ray?

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by QuentinLG · Dec 04, 2016 at 08:32 PM

Mesh colliders tend to be less precise/efficient than native colliders. Also they have special rules compared to natives.

From: https://docs.unity3d.com/Manual/class-MeshCollider.html

Collision meshes use backface culling. If an object collides with a mesh that will be backface culled graphically it will also not collide with it physically.

There are some limitations when using the Mesh Collider. Non-convex Mesh Colliders are only supported on GameObjects without a rigidbody. If you want to use a Mesh Collider on a rigidbody, it needs to be marked as Convex.

Try to mark your collider as convexe (if it make sense in your particular case). Convexe mesh colliders behave more logicaly.

Comment
Add comment · Show 4 · 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 parism9 · Dec 04, 2016 at 08:33 PM 0
Share

Why would this matter for raycasting?

avatar image QuentinLG parism9 · Dec 04, 2016 at 08:36 PM 0
Share

Raycasting only works against colliders, so it's possible that it shares the same weaknesses.

avatar image bpears · Dec 04, 2016 at 09:09 PM 0
Share

Fixed this issue a while back. Sadly I don't remember what it was, so I'll mark your answer correct because it is relevant. I think I reimported them or something to fix it. Actually it might have been floating point issue of where the mesh was placed, don't remember.

avatar image ZOM585 · Oct 30, 2018 at 12:20 AM 0
Share

Holy crap, this is indeed an issue. We searched for hours trying to figure out why our debug raycast was clearly going through a plane but the plane's collider.raycast was giving false for the same ray.

avatar image
1

Answer by drivenbeyond · Feb 28, 2016 at 02:23 PM


Are you logging what is being hit by the ray? It could in my experience be hitting something else. Whatever the issue, I can test if you'd like, can you send a link to the proj? I'm running hundreds of meshes in an area and getting hit data in my own proj :)

Comment
Add comment · Show 2 · 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 bpears · Feb 28, 2016 at 02:50 PM 1
Share

It isn't hitting anything, I have a debug right after if(Physics.Raycast . The mesh collider is the only collider it could hit at this position. Like I said with a primitive from unity it works fine. Are the meshes in yours imported? are they primitives? Primitives from unity work with box or mesh collider for me, but imported meshes it just doesnt like apparently.

I just tested a box collider on the imported mesh just to make sure something wasnt super wrong, but it works. So yeh, imported mesh with mesh collider is broken for me.

avatar image bpears · Feb 28, 2016 at 02:55 PM 0
Share

and yet, using some spheres with rigidbodies, they properly collide with the mesh and roll around.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

66 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 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 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 avatar image avatar image avatar image

Related Questions

Raycast problem 1 Answer

Does work the raycast on a mesh collider? 3 Answers

RaycastHit if/else Problem (bug?) 0 Answers

What is wrong about this RaycastHit Event??? 1 Answer

Raycasting help 2 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