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
0
Question by GregoryNeal · Nov 17, 2021 at 01:38 AM · raycastcollidersspherecastall

SphereCastAll is passing through colliders selectively

I'm trying to SphereCast between two objects to tell if a clean line of sight exists. You can see how my colliders look in the second picture. The center collider is on the root transform, and the outside ones are within child transforms. My code is very simple, it's:

     public bool TestValidPlacement(Transform st, Transform et) {    
         collisionTestingEndpoints[0] = st.position;
         collisionTestingEndpoints[1] = et.position;
 
         Vector3 dir = et.position - st.position;
         dir = dir.normalized;
         float dist = Vector3.Distance(st.position, et.position);

         Ray ray = new Ray(st.position, dir);
         Ray backRay = new Ray(et.position, -dir);
         RaycastHit[] sHits = Physics.SphereCastAll(ray, width/2f, dist);    
         RaycastHit[] sBackHits = Physics.SphereCastAll(backRay, width/2f, dist);
 
         Debug.DrawRay(ray.origin, ray.direction * dist, Color.cyan, 10f);
 
         if (sHits.Length > 0 || sBackHits.Length > 0) return false;
         return true;
     }

     private void OnDrawGizmos() {
         Gizmos.DrawSphere(collisionTestingEndpoints[0], width / 2f);
     }

By all accounts this collision should get picked up by SphereCastAll. The start point of the ray is clearly outlined by the gizmo, showing that it isn't initially overlapping any colliders. And the Debug ray clearly passes through two colliders. Both of which are on the default raycast layers. Even if somehow the forward SphereCastAll was initially inside a collider, then the backwards SphereCastAll would absolutely pick it up. But neither return any hits for this setup. Any help is appreciated.

alt text alt text

spherecast-going-through-two-colliders.png (80.5 kB)
collider-setup.png (115.8 kB)
Comment
Add comment · Show 4
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 CodesCove · Nov 17, 2021 at 05:50 PM 0
Share

Code should be ok.

few things to check..

width >0?

colliders are not in trigger mode? (or check from Project settings that Queries hit colliders is checked)

Is it intentional to return false if ShpereCast hits colliders?

avatar image GregoryNeal CodesCove · Nov 17, 2021 at 06:35 PM 0
Share

The width parameter is greater than 0, you can see the width parameter being used to do the SphereCast is the same width used to draw the gizmo, so you can see how big the SphereCast is in the photo. I just checked and verified the colliders are not in trigger mode. I have a "Queries hit Triggers" option that is checked, but no checkbox that says "Queries hit Colliders", however my layer collision matrix is all check marks, everything should collide with everything else. I am intentionally returning false if there is a collision and true if there is not.

How it works is this, you can move the "resistors" by picking them up from the center. If there is a "wire" attached it runs the above function to test if there is a clear line of sight between the sphere and the same spot just outside of that other resistor. The weird part is that I can grab the other resistor and have perfect collision detection. The only difference is that one end of the wire attaches to a transform stored in the "start" member and the other end attached to a transform with the member named "end". It runs this exact same function to check for collisions (in both directions). I've even verified that the exact same transforms are being sent to the TestValidPlacement function in both the working example and the non working example you see above.

avatar image CodesCove GregoryNeal · Nov 17, 2021 at 07:21 PM 0
Share

Strange.. I tested the code and both ways it worked just fine. If you have tested that rays are ok from both of these spots (the transform are correct) then I have no more ideas what could be the issue, sorry..

Btw. this might not be related to the issue, but in your 2nd picture there is some extra debug ray.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

184 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 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 not hitting the collider properly it always has a weird offset 0 Answers

Raycasting to make Buildings Clickable 1 Answer

Setting object to my own layer is making it fall through scenery. Why? 0 Answers

How to test colliders C# 2 Answers

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