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 /
  • Help Room /
avatar image
0
Question by rabblerousy · Jun 16, 2020 at 03:48 PM · collider2dlayersraycasthit2draycastalllayercollision

RayCastAll seemingly ignoring a particular collider

Hello everyone, I'm implementing an A* algorithm for a 2D point&click, based on Nodes. This is what I'm using as reference: http://www.jgallant.com/nodal-pathfinding-in-unity-2d-with-a-in-non-grid-based-games/

I have instantiated a two dimensional array of PathNodes (Prefab holding a PathNode component) that each have a Circle2D Collider on a Phsyic Layer called "NavMeshNode". They are placed inside the scene, roughly on the "Walkable Ground" gameObject's collider. alt text

Right now I am trying to instantiate the connections between each Node and it's potential 8 neighbours. I do not want to make connections between 2 Nodes that are separated by "Not Walkable" Ground (another GO holding only a collider).

This is the code I am using to Raycast in all 8 directions (called on each Node):

 for (int i = -1; i <= 1; i++)
 {
             for (int j = -1; j <= 1; j++)
             {
                 if (i == 0 && j == 0) continue;
 
                 RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position , new Vector2(i, j), nodeDist);
                 print(hits.Length + " Hits!");

I am then iterating through the hits Array, to check for "Not Walkable" and "NavMeshNode" Colliders hit.

 bool notWalkableGroundFound = false;
 PathNode nodeHit = null;
 foreach (RaycastHit2D hit in hits)
 {
           LayerMask l = hit.collider.gameObject.layer;
           print("Hit: " + LayerMask.LayerToName(l));
           if(l == LayerMask.NameToLayer("NotWalkable"))
           {
                     notWalkableGroundFound = true;
                     break;
            } else if(l == LayerMask.NameToLayer("NavMeshNode"))
           {
                      nodeHit = hit.collider.GetComponent<PathNode>();
            }
 }
 if(!notWalkableGroundFound && nodeHit != null)
 {
           if (neighbours == null) neighbours = new List<PathNode>();
           neighbours.Add(nodeHit);
 }

And here's my problem: I am hitting EVERY Collider in that area (Phsyic Layers "Walkable", "Clickable" (Ground that can be clicked, but not walked), "Not Walkable") but not a single NavMeshNode Collider (or even "Default").

alt text

So apparantly, RaycastAll() is somehow not detecting the Colliders of my NavNode GameObjects.

Some things I tried to fix it:

  • Call the RaycastAll() method from another GO (currently it's being called on each of the Nodes)

  • Add an offset to the raycast position, to make it start outside of its own NavMeshNode collider

  • Changed the z-Positions and Phsyic Layers in various ways

  • Gave the parent GO of the nodes a collider (this gets detected)

PLEASE someone help me with this, I am really out of ideas... Thanks a lot in advance!!

unbenannt.png (33.6 kB)
unbenannt.png (311.8 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

205 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Stucking with RTS Building detection using 2D Raycasts and 2DBoxColliders 0 Answers

Select all layers in the scene except the triggers 0 Answers

RaycastAll from prefab is not picking up a collider from another prefab 1 Answer

How to trigger functions like OnTriggerEnter2d and OnTriggerExit2d with raycasthit2d ? 1 Answer

Collider2d cast to player child ignores the child 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