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 khoatic · Feb 18, 2014 at 07:14 AM · collisionphysicscollideroverlay

Physics.OverlapSphere not giving proper coordinates

So Im trying to use Physics.OverlapSphere to get a set of objects around the object with the attached script. when testing its showing their locations to be exactly the same, I cant figure out why, please help.

///////////////////////////////////////////////////////////////////////////// Update Class /////////////////////////////////////////////////////////////////////////////

 private List<GameObject> rootNodeList;
 private GameObject curRoot = null;
 private GameObject nextRoot = null;
 void Awake()
 {
     rootNodeList = new List<GameObject>();
 }
 void Update () 
 {
     int val = Random.Range(0, rootNodeList.Count);
     curRoot = rootNodeList[val];
     if (curRoot == null) { Debug.Log("Error:current Root is Null"); }
     curRoot.GetComponent<RootNode>().findLinks();
     nextRoot = curRoot.GetComponent<RootNode>().pickNextNode();
     if (nextRoot == null) { Debug.Log("Notify:current Root has no connections"); }
     curVec = nextRoot.transform.position - curRoot.transform.position;
     Debug.Log(nextRoot.transform.position);
     Debug.Log(curRoot.transform.position);
  }

///////////////////////////////////////////////////////////////////////////// RootNode Class /////////////////////////////////////////////////////////////////////////////

 private List<GameObject> linkedNodes;
 void Awake()
 {
     linkedNodes = new List<GameObject>();
 }
 public void findLinks()
 {
     Collider[] linkedObjects = Physics.OverlapSphere(this.transform.position, linkRadius);
     Debug.Log(linkedObjects.Length);
     for (int i = 0; i < linkedObjects.Length; i++)
     {
         if (linkedObjects[i].tag == "ROOTNODE")
         {
             linkedNodes.Add(linkedObjects[i].gameObject);
         }
     }
 }
 public GameObject pickNextNode()
 {
     int val = Random.Range(0, linkedNodes.Count);
     if (linkedNodes.Count <= 0) { Debug.Log("Notify: there is no Nodes around"); }
     return linkedNodes[val];
 }
Comment
Add comment · Show 2
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 getyour411 · Feb 18, 2014 at 07:32 AM 0
Share

Nothing is jumping out at me on this - after 14 in RootNode maybe do Debug.log(linkedObjects[i].tranform.position.ToString()) to see if the bounding volumes are reporting the same t.pos

avatar image khoatic · Feb 18, 2014 at 08:30 AM 0
Share

Thats what seems to be happening, the positions are the same and i cant figure out why its happening.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wibble82 · Feb 18, 2014 at 08:54 AM

The only cause I can think of is if linkedObjects.Length is 1. In your loop on line 10 of the root node class you don't explicitly ignore 'this', so the sphere test is going to return the current root node in addition to any others nearby. As a result the rest of your code would always end up looking at the same object.

Try giving each of your root nodes a different name, then printing out the name of each linkedNode inside that for loop. If it always prints out the same name then there's your problem, probably solved by:

  1. Ignoring the node corresponding to 'this' inside the for loop

  2. Making sure the radius you're searching for is large enough to detect other objects nearby

The only other possible cause I could think of would be if you had a hierachy for each of your nodes, and the root nodes were staying in the same place but their children where moving (if, for example, the child nodes have rigid bodies that move under physics but the root nodes don't). This would be pretty obvious in the editor though.

-Chris

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

20 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

Related Questions

Best collision detection method? 2 Answers

Projectiles, their speed, and collisions 1 Answer

overlapsphere to destroy NPCs on exit 1 Answer

How to stop my sword from hitting myself 2 Answers

How do I get the player and the object they touch both disappear/destroyed? 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