Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
0
Question by Steven-1 · Apr 11, 2013 at 09:27 PM · raycastcollidermeshraybackface

Creating a working meshcollider in code

I want to do raycasts on a mesh, now it appears that raycasts only hit front facing triangles, but I want it to hit both back and front facing triangles.

Unfortunately this doesn't seem to be optional, so instead I make a new mesh, copy all vertices and triangles, and add all triangles again in reversed order. And then assign this new mesh to the collider.

Now here's the problem, when I do this, every and any raycast results false.

Unless, I first make the collider and keep it in the scene, then select it and change some values (and set these back to how they where before), and then do the raycasts, and then it suddenly does work.

So what's wrong? (and how do I fix it?) It's as if something needs to happen to a new mesh before it can be used, something that happens automatically, but not immediately it seems.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Steven-1 · Apr 12, 2013 at 10:15 AM

Found the answer here: http://answers.unity3d.com/questions/14465/how-to-assign-procedural-mesh-to-a-collider.html and here: http://answers.unity3d.com/questions/171571/dynamic-mesh-collider.html

It appears it works if you first create the mesh and then assign it to the collider, rather than assigning a new empty mesh, and then setting the vertices and triangles (which was what I actually did). Otherwise it also works, but only after 1 frame or so.

Comment
Add comment · 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
0

Answer by OP_toss · Apr 11, 2013 at 10:52 PM

Ew don't do that. 2 overlapping colliders in the same mesh?!

Instead make 2 colliders, one with front-faces, one with back-faces. Unless of course there's some way to switch off backfacing for collision meshes that I don't know about...

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 DaveA · Apr 11, 2013 at 11:00 PM 0
Share

Please use Answer when answering a question

avatar image Steven-1 · Apr 12, 2013 at 07:45 AM 0
Share

the collider is only used for raycasts, so I doubt this has any disadvantage over having 2 colliders. Regardless, that's not the issue, if I make a new mesh that's just the exact same mesh as the original, the problem is still there

avatar image
0

Answer by Hyarch · Feb 27, 2015 at 07:30 AM

All Wrong Your Probably Assigning The Mesh Colliders to a Parent of a Mesh Object or fbx

if 2 overlapping colliders Ignore Layer in settings

   foreach(Transform child in modelobj.transform){
                       MeshCollider ObjCollider = child.transform.gameObject.AddComponent("MeshCollider") as MeshCollider;
                   }
Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Mesh Collider Issue(?) - Raycast (ScreenPointToRay) Appears to Collide on Nothing 0 Answers

Raycast isnt working 1 Answer

Is there a way to detect if an object is being hit by a raycast? 2 Answers

I don't know why i can't detect by ray sth. tagged, 1 Answer

Raycast to align character on MeshCollider normals 1 Answer


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