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 /
avatar image
0
Question by HittmanA · Dec 07, 2016 at 08:57 PM · 3dgameobjectsneighbour

Finding a GameObjects neighbors in a 3D space

I have a bunch of GameObjects in a scene. I need each GameObject to know the location and rotation of its neighbours (within a certain range). What is the best and fastest way to find the location and rotation of a GameObject's neighbours within a certain range? Can someone provide an example? Thanks in advance!

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 Spartiate0033 · Dec 07, 2016 at 11:17 PM 0
Share

I understand your question, but what exactly are you trying to do? A bit more context would be appreciated

avatar image HittmanA Spartiate0033 · Dec 08, 2016 at 03:01 AM 0
Share

I simply want to be able to get the position and rotation of neighbooring objects and then manipulate them.

2 Replies

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

Answer by JC_SummitTech · Dec 07, 2016 at 11:54 PM

Physics.SphereCast centered on the core object to get a list of objects in range, then grab these object's transforms

Comment
Add comment · Show 2 · 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
avatar image HittmanA · Dec 08, 2016 at 03:00 AM 0
Share

Could you provide a simple example? (I am pretty new to this)

avatar image lylat HittmanA · Dec 08, 2016 at 03:10 AM 1
Share

the API is here: https://docs.unity3d.com/ScriptReference/Physics.SphereCast.html

Spherecast basically shoots a sphere along a path and returns whether it hit anything. if you make the distance 0 then it will just return what was in the sphere at distance 0.

Just look at that link, it has a good example on how to use it and you can modify it for yourself.

avatar image
0

Answer by lylat · Dec 08, 2016 at 08:12 AM

What you are looking for is :

 Physics.OverLapSphere

https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

Basically creates a sphere collider for a single frame and checks to see if it collided with anything, you would need to make the objects you are checking against have colliders, but it is also possible to give them triggers if that is not what you want to do. (Detail in the docs on how to do this).

What @JC_SummitTech said is also viable.

Comment
Add comment · Show 1 · 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
avatar image JC_SummitTech · Dec 08, 2016 at 01:55 PM 0
Share

You are right, this would be more appropriate than a SphereCast.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need to increase position of multiple prefabs by the same number 0 Answers

Can I assign different surfaces of the same GameObject different tags?,Is it possible to make certain surfaces of GameObjects have different properties/tags? 0 Answers

How do I make a child stay with parent object? 1 Answer

How to make only this red area clickable on the cube ? 0 Answers

Make my 3D Game resolution fit all mobile devices 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