Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 dropeliciouse · Apr 25, 2019 at 02:30 PM · raycastcollision detectionraycastingmeshcolliderprocedural mesh

Raycasting not working on a procedural mesh with a mesh collider.

I wrote some code that creates a procedural mesh made out of smaller cubes, its basically the same as the code on this video only it supports 3 dimensions (X,Y,Z):

https://www.youtube.com/watch?v=bFKgiPomYpM

The problem is that it does not detect the mesh collider when ever a ray is cast at it, it just goes trough as if nothing was there.

Here is the code used for the collision detection:

  private void Update(){
         UpdateVoxelMesh(data);
         UpdateMesh();
 
         //Rayrace to get the click position
 
         if (Input.GetMouseButtonDown(0)){
             Vector3 clickPosition = -Vector3.one;
 
             Plane plane = new Plane(Vector3.up,0f);
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             float distanceToPlane;
 
             if (plane.Raycast (ray, out distanceToPlane)){
                 clickPosition = ray.GetPoint (distanceToPlane);
             }
 
             print(clickPosition);
         }
 

Some Images: alt text

alt text

capture2.png (51.6 kB)
capture.png (200.5 kB)
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 Bonfire-Boy · Apr 25, 2019 at 04:24 PM 0
Share

Your mesh collider doesn't have a mesh associated with it. Assign the same mesh as in the mesh filter component. If you remove and then re-add the $$anonymous$$esh Collider component then it should do this automatically.

avatar image JonnyHilly · May 02, 2020 at 01:08 AM 0
Share

I have the same problem... procedural mesh.... except $$anonymous$$e has been working for a few years... updated Unity to 2019.1 now it doesn't work anymore. I have the mesh collider assigned. Unity physics collides with the mesh, but ray-cast does not work anymore. The layering is correct, nothing else changed. I tried setting the collision mesh to null, right before re-assigning it again. doesn't work.

I see there are new options to do with "$$anonymous$$eshColliderCookingOptions" on the component now... but they don't seem to fix things....

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BBIT-SOLUTIONS · May 02, 2020 at 01:25 AM

Some ideas, maybe one of them could help you:

  • Try setting convex on your Mesh Collider

  • Try using a BoxCollider instead of the MeshCollider

  • Instead of using ScreenPointToRay() you could try using ViewportPointToRay()

  • Use a Physics.Raycast instead of the Camera.main.raycast

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

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

RayCast2D problems on collision detection 3 Answers

Raycast not hitting collider 2 Answers

Raycast exit point of collider 0 Answers

How do i get local Hit position of Raycast on a collider 1 Answer

How can I let the ray to the edge of the capsule? 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