Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 rnhfjkui · May 21, 2016 at 12:33 PM · raycastingmeshcollider

Raycast stops on a mesh collider on empty parts of the collider.

I found a problem in my game where the raycasting doesn't seem to work with the mesh colliders very well, it seems to collide with them not only on their surface, happens in more cases then the examples i show here and happens constantly in these places so it is not a passing behaviour.

the code:

 if (Input.GetKeyDown(KeyCode.Mouse0))
         {
             RaycastHit Hit;
             Ray R = new Ray(gameObject.transform.position, transform.forward);
             Physics.Raycast(R, out Hit, Max);
             if (Hit.collider != null && Hit.collider.tag != "Object" && Hit.collider.tag != "Slide" && Hit.collider.tag != "Floor" && Hit.collider.tag != "NoSoundFloor" && Cursor.lockState.Equals(CursorLockMode.Locked))
             {
                 LR.enabled = true;
                 LR.SetPosition(1, Hit.point);
                 //   trKek.position = Hit.point;
                 temp.transform.position = Hit.point;    
                 confirm = true;
                 gp = true;
                 tr.GetComponent<Rigidbody>().freezeRotation = false;
                 h.xMotion = ConfigurableJointMotion.Locked;
                 h.yMotion = ConfigurableJointMotion.Locked;
                 h.zMotion = ConfigurableJointMotion.Locked;
                 h.anchor = temp.transform.localPosition;
                 //    lastTime = Time.time;
             }
             Debug.LogError(Hit.collider.name + "; " +Hit.distance + "; " + Hit.point);
         }

and here is one instance of it happening:

alt text

alt text

Last thing i must note is that the raycast IS hitting the mesh collider for sure as in the Debug it shows the mesh collider's name under Hit.collider.name I would be very happy to get any help on the matter.

screenshot-13.png (380.3 kB)
screenshot-16.png (223.6 kB)
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

2 Replies

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

Answer by rnhfjkui · May 22, 2016 at 01:39 AM

FIXED IT if anyone is interested the imported mesh collider MUST be collada type because FBX was making the problem. i don't know why tho it is kind of weird but everything is fixed.

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 HashGrove · Jul 30, 2016 at 10:15 PM 0
Share

You, my friend, have saved me more than you can imagine. Thank you, this fixed it for me too.

avatar image Ayudat · Jan 19, 2017 at 04:44 PM 0
Share

Omg!! You life saver. I nearly gave up a whole dream until I saw this solution. Thank you so much. I will mention you in the thank you credits (if I ever get there) lol.

avatar image
0

Answer by S4UC1SS0N · Aug 23, 2016 at 05:53 PM

Thank you so much for this ! It was making me crazy for a week ! You rock.

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

7 People are following this question.

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

Related Questions

Ray cast not hitting the backside of mesh collider attached to a spherical mesh object 0 Answers

Find closest point on all objects in a layermask 1 Answer

My characters in Unity float slightly above my ground I imported and made in Blender 0 Answers

Physics.Boxcast not working with mesh collider 1 Answer

Raycasting not working on a procedural mesh with a mesh collider. 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