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 08, 2021 at 02:37 AM · raycastlinerendererraycastall

RaycastAll will not detect any colliders

Hi I'm trying to use RaycastAll to determine if a line renderer should be able to draw a line between two colliders. The problem is that RaycastAll will not detect anything.

Here is a slightly simplified version of the code I'm using to determine if a linerenderer should draw the line between colliders:

 public bool IsValidPlacement() {
     Vector3 dir = end.position - start.position;
     dir = dir.normalized;
     Debug.DrawLine(start.position, end.position, Color.black);
     float dist = Vector3.Distance(start.position, end.position);

     bool isValid = true;
     Ray ray = new Ray(start.position, dir);
     int i = 0;
     RaycastHit[] hits = Physics.RaycastAll(ray, dist);
     print("Found " + hits.Length.ToString() + " hits from start to end.");
     foreach (RaycastHit hit in hits) {
         Debug.DrawLine(start.position, hit.point, Color.Lerp(Color.green, Color.blue, (float)i/hits.Length));
         i++;
         string tag = hit.transform.tag;
         if (!tag.Contains("Component Input")) {
             isValid = false;
         } else {
             Transform wl = hit.transform.Find("wire location");
             if (wl != start && wl != end) {
                 isValid = false;
             }
         }
     }
     }

     return isValid;
 }


Where start, end are of type Transform and defined as members.

The problem can be seen in the below picture. The black ends of the rectangular prisms are potential start and end points for the LineRenderer. In this example the black line in the center is being generated by the first Debug.DrawLine in my method. And you can see it is actually going all the way through the prism on the left because the start point is the left most black tip, this black line is going through 3 colliders: the furthest left black end of the prism, the center pink part which has it's own collider, and the right side of the prism.

alt text

However I'm still getting "Found 0 hits from start to end" despite using the same start position and distance for RaycastAll that I use to draw the debug line. Where it should find 3 hits.

You can see in the below picture that the prefab is indeed made up of 3 colliders.

alt text

I am at a complete loss as to why this is happening, and thus feel like I'm missing something basic about RaycastAll. Any help is very appreciated.

unity-0sg7q4izuk.png (207.2 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

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

181 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

Related Questions

ScreenPointToRay ray not coming through from camera 0 Answers

Linecast questions. 1 Answer

Multiple objects with OnMouseDown 2 Answers

How to make Raycast against LineRenerer 1 Answer

Raycast.distance giving me the wrong number 2 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