Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by microp · May 12, 2011 at 09:21 PM · raycastbugmeshcolliderignorespherecast

RayCast ignoring mesh colliders?

Hi,

I'd just like to reiterate this question from six months ago, as there was no answer. How do Ray- and Sphere- and WhatnotCast() treat mesh colliders?

My tests seem to suggest that the casts simply ignore mesh colliders. Mine was convex.

Thanks!

Comment
Add comment · Show 3
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 microp · May 17, 2011 at 05:17 PM 0
Share

As mentioned below, I made a simple test scene consisting of a central object and a few orbiting colliders. The central object has a script that calls SphereCastAll() and the other objects have various kinds of colliders. It happens that of the mesh colliders, only the sphere and capsule meshes registered as hits. Can anyone confirm these results?

avatar image microp · May 17, 2011 at 07:25 PM 1
Share

Just found out that Physics.SphereCastAll() ignores objects "behind" the starting point even though they're in the sphere. Nice.

avatar image microp · May 17, 2011 at 07:28 PM 0
Share

It seems like that might've been my problem all along. The behavior of SphereCast() is VERY erratic when it comes to the placement of the origin.

2 Replies

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

Answer by microp · May 17, 2011 at 08:44 PM

SphereCasts have trouble detecting objects that are within the radius around their origin, especially those behind the casting direction. In the case of my 2d game, I started the SphereCast X units above the gameplay plane and made it go X units below. That seems to catch everything properly.

I definitely consider this a bug and lost a lot of time to it. How do I report it so that others don't have to go through all of this?

Comment
Add comment · 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 Eric5h5 · May 17, 2011 at 08:46 PM 0
Share

Use the bug reporter app.

avatar image
1

Answer by Eric5h5 · May 12, 2011 at 09:54 PM

Raycasts do not ignore any colliders, mesh or otherwise, unless set up to do so with layers. They will "go through" the back sides of polygons, just like the back sides of polygons are (usually) invisible.

Comment
Add comment · Show 3 · 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 microp · May 12, 2011 at 11:41 PM 0
Share

That's very odd. The faulty object is on a layer that my SphereCast is set up to collide with. It's ignored when it has its mesh collider, but if I switch that for a sphere collider, and nothing else, everything's fine. Both are non-triggers, and normal collisions with rigidbodies work fine too. Only the SphereCast fails. I'll investigate further.

avatar image microp · May 13, 2011 at 04:29 PM 0
Share

I don't believe it. I set up an empty test scene. It turns out that sphere and capsule mesh colliders are caught correctly, but any other mesh fails, built-in or custom.

avatar image Rajeesh_AR · Feb 15, 2016 at 05:44 AM 1
Share

I also have the issue with the type of collider that Raycast detect.. It detects on Box Collider & Sphere collider correctly , but not detecting $$anonymous$$esh or Capsule collider. It detects the capsule collider once in thousand clicks..

Here is my code:

 void Update () 
 {    
     if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftAlt))
     {
         RaycastHit hit;
         Ray ray = new Ray (transform.position, transform.forward);
         
         if(Physics.Raycast(ray,out hit , 1000f))
         {    
             Debug.Log(hit.collider.gameObject.tag.ToString());
             if(hit.collider.gameObject.tag == "Enemy")
             {
                 Debug.Log(".. hit the enemy");
             }
         }
     }
 }

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

2 People are following this question.

avatar image avatar image

Related Questions

Why do I get a triangleIndex of -1 when I SphereCast a convex MeshCollider? 1 Answer

How to scan a surface of a GameObject and get the distance of every edge to camera 1 Answer

RaycastHit Triangle Index Problem 0 Answers

Raycast not ignoring layer 0 Answers

Make a cursor following 3D surface in Unity 3D 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