Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Programmer_Jon · May 02, 2016 at 10:50 PM · c#3d

Checking if GameObject is withing an other GameObject?

I am working on a tower defence game, ive got the pathing working. but what im having issue with is:
I am creating the nodes for the path finding script dynamical and what i am trying to do is to delete the nodes that appear inside a wall. i cant use trigger colliders since it kills the pathing thinking the nodes are blocking everthing.

Here is the code creating the nodes and then checking if its inside a wall:

    private void CreateNodes(){
     for(int z = 0 - (int)numNodesHorizontal / 2; z < numNodesHorizontal - (int)numNodesHorizontal / 2; z++)
     {
         for(int x = 0 - (int)numNodesLength/ 2; x < numNodesLength - (int)numNodesLength / 2; x++)
         {
             GameObject node = Instantiate(nodePrefab) as GameObject;
             node.transform.parent = transform;
             node.transform.localScale  = new Vector3(1,1,1);
             node.name = "Node: x: " + x + ", z: " + z + ".";
             node.transform.localPosition = new Vector3(x, 5, z);
             nodes.Add(node);
         }
     }
 }
 
 void DestroyNodes(){
     for(int i = 0; i < nodes.Count; i++){
         for(int w = 0; w < walls.Length; w++){  
             if(nodes[i].transform.TransformPoint(nodes[i].transform.localPosition).x - nodes[i].GetComponent<Collider>().bounds.size.x >= walls[w].transform.localPosition.x - (walls[w].GetComponent<Renderer>().bounds.size.x / 2) && 
             nodes[i].transform.TransformPoint(nodes[i].transform.localPosition).x + nodes[i].GetComponent<Collider>().bounds.size.x <= walls[w].transform.localPosition.x + (walls[w].GetComponent<Renderer>().bounds.size.x / 2) &&
             nodes[i].transform.TransformPoint(nodes[i].transform.localPosition).y - nodes[i].GetComponent<Collider>().bounds.size.y >= walls[w].transform.localPosition.y - (walls[w].GetComponent<Renderer>().bounds.size.y / 2) &&
             nodes[i].transform.TransformPoint(nodes[i].transform.localPosition).y + nodes[i].GetComponent<Collider>().bounds.size.y <= walls[w].transform.localPosition.y + (walls[w].GetComponent<Renderer>().bounds.size.y / 2) &&
             nodes[i].transform.TransformPoint(nodes[i].transform.localPosition).z - nodes[i].GetComponent<Collider>().bounds.size.z >= walls[w].transform.localPosition.z - (walls[w].GetComponent<Renderer>().bounds.size.z / 2) &&
             nodes[i].transform.TransformPoint(nodes[i].transform.localPosition).z + nodes[i].GetComponent<Collider>().bounds.size.z <= walls[w].transform.localPosition.z + (walls[w].GetComponent<Renderer>().bounds.size.z / 2) ){
               Destroy(nodes[i]);                   
             }
         }            
     }
 }
Comment
Add comment · Show 5
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 Programmer_Jon · May 02, 2016 at 11:05 PM 0
Share

As you see in the screen shot below it deletes only a few and not anywhere where im checking. alt text

screen1.png (263.0 kB)
avatar image Toon_Werawat · May 02, 2016 at 11:16 PM 0
Share

Did you try to store it in List And destroy it later?

avatar image Programmer_Jon Toon_Werawat · May 02, 2016 at 11:19 PM 0
Share

They are stored in a list, and after they are created they are destroyed.

avatar image Toon_Werawat · May 03, 2016 at 09:20 AM 0
Share

$$anonymous$$aybe try destroy it later? Invoke by a few seconds to destroy it?

avatar image Programmer_Jon Toon_Werawat · May 03, 2016 at 05:23 PM 0
Share

its destroying some of them but not the right ones

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

152 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

Related Questions

Score won't work 1 Answer

Struggling with bounce pad in platformer game. 1 Answer

Best Way To Have An Enemy NPC Chat With Player 0 Answers

How do I load tiles at runtime? 0 Answers

What is the different between OnTriggerEnter and OnCollisionEnter ? 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