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 saarwii · Apr 04, 2014 at 09:19 PM · loopphysics.overlapsphere

physics.OverlapSphere and loops troubles

Hi! having some troubles with my loops. So this is what im doing and need to do. Im moving an object with transform. I have to do it this way for technical reasons. Now, i have to have some collision detection on this object, yea i know, transform.position and collisions is not the way to go but i have to do it this way so im OverlapSphere to check collision. I have to be able to detect if my object is hitting something from all points around it so a normal RayCast wont do.

It's like a selecting feature or, when you mouse over and objects in some game, they light up, but this is in 3d space and i use game objects to do it.

Now here is the part where im having trouble getting it to work the way i want it to.

When my object is colliding with another object in the world i want the moving object to turn of it's renderer and the object i hit, i want to change the material on. now, i got this to work, half way. i can turn of my moving objects renderer and change the material on the other object. But when i move away from object i hit, i want the moving objects renderer to turn on and the material of the hit object to go back to normal. I cant get this last part to work.

i've tried

  Collider[ ] hitColliders = Physics.OverlapSphere(transform.position,     radius);
 
     foreach(Collider hit in hitColliders){
     //check if im hitting an object that i want to light up
     if(hit.tag == "interactive"){
     renderer.enable = false;
     }
     //if im not hitting anything
     if(hit.tag == null){
     renderer.enable = true;
     }
     }

the problem i guess is it only does loops while im hitting an object, so it knows im hitting something, but as soon the two objects colliders isnt overlapping anymore, it stopps doing anything...I've tried alot of different ways of writing it but im stuck`enter code here`

Comment
Add comment · Show 1
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 Owen-Reynolds · Apr 04, 2014 at 10:22 PM 0
Share

So, not a problem with OverlapSphere. Really a commonish program$$anonymous$$g "no auto reset" problem.

The trick is to remember the objects that were hit, and specifically check if they are now out of the area. Could spawn a coroutine for each, that checks every frame. Or could put them on a list that you check every frame. A shortcut, for "am I out of range yet?" would be to just check distance to the object.

Or, poor mans's hack: before doing the overlap check, reset everything's color.

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

22 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

Related Questions

Infinite Looping Crash 2 Answers

My particle emitter stops emitting once the W key is released but doesnt start when it is pressed again 2 Answers

Pre-Determined Path for Helicopter 1 Answer

For loop not working 1 Answer

iTween - How to move an object that is currently undergoing a "tweening"? 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