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 CloodStool · Jan 04, 2021 at 10:18 PM · collidersoverlapping

Checking for dead ends with Physics.OverlapBox()

Unity version: 2019.4.11f1

Hi, I'm having an issue trying to detect dead-ends in my game board generation. So far steps 1 to 6 work as intended, and yield a random board every time, comprised of tiles and paths generated at random, like so:



Now what I'm trying to do with step 7b is: for each path that isn't inactive, check if it's a dead end.

The way I'm trying to go about this is: for each path that isn't inactive, add a OverlapBox() at each extremity that counts the number of active game objects. If that number is one (meaning it found only the path it's checking from), then it's a dead end.

When I run that part of the script though, I get this:



What I suspect is the problem (idk if it really is that) is that instead of creating the boxes A and B at +/- y relative to the game objects, it's adding or subtracting y relative the the world. Again, it could be something else entirely, I'm really not sure.

Here's the method called by step "7b - Remove Dead Ends":


 public void RemoveDeadEnds()
     {
         Debug.Log("RemoveDeadEnds() started");
         // maybe I need to make everything active at the start (and then deactivate untagged at the end)?
 
         // for each path that isn't untagged, get their hitCollisions
         for (int i = 0; i < allPaths.Count; i++)
         {
             if (!allPaths[i].gameObject.CompareTag("Untagged"))
             {
                     // this part is fucked, I don't think it places the boxes at the correct position. I suspect it adds the new Vector3() +/- y relative to the world, instead of the gameobject
                 Collider[] hitCollidersA = Physics.OverlapBox(allPaths[i].gameObject.transform.position + new Vector3(0, allPaths[i].gameObject.transform.lossyScale.y / 2, 0), new Vector3(0.4f, 0.4f, 0.8f)); // removed: allPaths[i].gameObject.transform.localRotation
                 Collider[] hitCollidersB = Physics.OverlapBox(allPaths[i].gameObject.transform.position + new Vector3(0, -allPaths[i].gameObject.transform.lossyScale.y / 2, 0), new Vector3(0.4f, 0.4f, 0.8f)); // removed: allPaths[i].gameObject.transform.localRotation
 
                 if (hitCollidersA.Length == 1) //I don't understand if it should be 1 or 2 help (en vrai ils ont pas l'air de se voir eux-même donc 1 paraît correct)
                 {
                     Debug.Log("RemoveDeadEnds() - " + allPaths[i].gameObject.name + ": DEAD END (hitCollidersA)");
 
                     for (int n = 0; n < hitCollidersA.Length; n++)
                     {
                         Debug.Log("hitCollidersA[" + n + "] = " + hitCollidersA[n].gameObject.name);
                     }
 
                     allPaths[i].gameObject.tag = "DeadEnd";
                     allPaths[i].gameObject.GetComponent<MeshRenderer>().material.SetColor("_Color", Color.yellow);
                 }
 
                 if (!allPaths[i].gameObject.CompareTag("DeadEnd"))
                 {
                     if (hitCollidersB.Length == 1)
                     {
                         Debug.Log("RemoveDeadEnds() - " + allPaths[i].gameObject.name + ": DEAD END (hitCollidersB)");
 
                         for (int n = 0; n < hitCollidersB.Length; n++)
                         {
                             Debug.Log("hitCollidersB[" + n + "] = " + hitCollidersB[n].gameObject.name);
                         }
 
                         allPaths[i].gameObject.tag = "DeadEnd";
                         allPaths[i].gameObject.GetComponent<MeshRenderer>().material.SetColor("_Color", Color.yellow);
                     }
                 }
 
                 if (!allPaths[i].gameObject.CompareTag("DeadEnd"))
                 {
                     Debug.Log("RemoveDeadEnds() - " + allPaths[i].gameObject.name + ": skip");
                 }
 
                 // set newly deactivated path's tag to "Untagged" and color white
             }
         }
     }


Thanks in advance for any help or input!

onpaste20210104-190525.png (314.2 kB)
onpaste20210104-190556.png (316.0 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

1 Reply

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

Answer by CloodStool · Jan 05, 2021 at 04:24 PM

Aaaand I found the answer!

https://answers.unity.com/questions/1125044/how-do-i-move-an-object-relative-to-another-object.html

OP also found the answer themselves funilly enough ^^ instead of doing + new Vector3(0, allPaths[i].gameObject.transform.lossyScale.y / 2, 0) I had use transform.TransformDirection() like so: + allPaths[i].gameObject.transform.TransformDirection(new Vector3(0, allPaths[i].gameObject.transform.localScale.y / 2, 0))

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

112 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

Related Questions

Objects overlapping at origin (0,0,0) (question about OverlapSphere?) 0 Answers

Checking if object intersects? 1 Answer

Overlapping instances of the same object trigger collision more than once 1 Answer

physics.OverlapSphere colliders 1 Answer

Unity 5 no terrain collision 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