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
1
Question by acriticalstrike · Jun 07, 2013 at 01:07 PM · savesphere

Can I grow a sphere collider and collect object vectors and object information from a scene and add this data to a list?

Can I grow a sphere collider and collect object vectors and object information from a scene and add this data to a list?

My idea is that I would like to grow a sphere in size over a short amount of time and each time the sphere collides with an object I want to record the vector of that object so that I can save these locations to a list. So I have a sphere collider trigger that grows in my scene now how do I get the vectors of all the objects it collides with as it grows?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by aldonaletto · Jun 07, 2013 at 01:25 PM

You could use Physics.OverlapSphere, but this function isn't very precise because only the bounding boxes are taken into account - a long object rotated 45 degrees about Y may be added to the list even if its body actually isn't even being touched. A more precise solution is to instantiate the trigger object, force collision calculation, get the objects with OnTriggerEnter and then delete the trigger - an answer on this subject can be found here.

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 acriticalstrike · Jun 07, 2013 at 01:43 PM 0
Share

thanks for the response :-)

avatar image
1

Answer by robertbu · Jun 07, 2013 at 01:54 PM

Whenever I have questions like this one I just test it. Surprisingly enough it does work with triggers (and I did not expect it to). I created a sphere, made the collider a trigger, added a rigidbody, turned off gravity, and added this script:

 #pragma strict
 
 function Update() {
     var sp : SphereCollider = GetComponent(SphereCollider);
     sp.radius += 0.01; 
 }
 
 function OnTriggerEnter() {
     Debug.Log("Triggered Something");
 }

Note it also worked if the growth was done in a 'for' loop in start as well. It did not work if the rigidbody has isKenematic enabled.

I'm not sure what information you are trying to collect with this code. From an efficiency point of view, you'd might be better off to use Physics.OverlapSphere() to collect all the possible game objects, cast rays (Collider.Raycast()) to each object to find the front distance to the collider, and then sort the result.

Comment
Add comment · Show 3 · 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 acriticalstrike · Jun 07, 2013 at 02:02 PM 0
Share

I'm trying to make a save script and I need to collect all the objects of the scene and I'm thinking I need to first know the transform locations of all the objects in the scene to do it. I like the answers so far but I'm still trying to write a solution to this problem.

avatar image robertbu · Jun 07, 2013 at 02:24 PM 0
Share

If you want to find all the active game objects, you can just do:

 var gos : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];

Note in most games, you will not want all the game objects, just game objects of a certain kind. The typical way to solve that problem is to tag the game objects and use GameObject.FindGameObjectsWithTag().

avatar image acriticalstrike · Jun 07, 2013 at 02:32 PM 0
Share

very interesting!

avatar image
0

Answer by GodClaw · Jun 07, 2013 at 02:26 PM

Add all of your game objects to a list and use a foreach loop.

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 acriticalstrike · Jun 08, 2013 at 12:30 AM 0
Share

how do i know how many prefabs have been instantiated? Doesn't each prefab have a unique name when it is instantiated during gameplay?

avatar image GodClaw · Jun 08, 2013 at 05:19 AM 0
Share

I'm on my phone but something like this..

 GameObject temp = instantiate(blah blah);
 objectlist.add(temp);
 
 foreach(GameObject gobj in objectlist)
 {
    //use gobj to find all the values
 }

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

16 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

Related Questions

Saving Whole Scene ? 0 Answers

PlayerPrefs HighScore problems, it doesn't work. 4 Answers

PlayerPrefs.GetInt won't load when awake. 0 Answers

Getting any type in Unity Inspector 1 Answer

Save lightmap in prefab 3 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