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 Hydroque · May 28, 2013 at 02:53 AM · javascriptcollisionobject

Collision Detection with object already in detection area

Hello! Okay so I extended the AOE of my block. When it has a intruder in it, my block begins rotating and firing. The thing is, if there is already another block inside it, and i turn my variables off for making the block fire, the block already inside the AOE is not shot at. It is not my variables. It's detection. I have a OnTriggerEnter() function as so function OnTriggerEnter(enemy : Collider){

     if(s == false){
         target = enemy.gameObject;
         s = true;
 
     }
 
 }

I have figured that when my block gets detected, it gets stopped from being detected because it has to enter it right when it needs to.

I have thought up two solutions.

Making a table and a run-through of objects to be shot at Leave as is and move the position of my blocks

What would the best solutions to my problem, how to detect objects already in detection area, when the objects cannot be detected inside the AOE?

Thanks, Hydroque!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 28, 2013 at 02:56 AM

If you are okay with your area of effect being a sphere, you can use Physics.OverlapSphere(). OverlapSphere() returns a list of colliders within the area. You could then attack them in order or you could pick one at random.

Comment
Add comment · Show 5 · 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 Hydroque · May 28, 2013 at 12:04 PM 0
Share

Relooking into the functions, I see that it makes a table with all the things inside the sphere. The thing is it sends a message. How would I be able to get gameObject out of these? Or are they already inside it? Thanks :)

avatar image robertbu · May 28, 2013 at 01:11 PM 0
Share

This would not require a new block. You specify a radius in OverlapSphere(). If you want to fire on the closest one, you will have to look through the list and find the closest and make it a target. You could call it each frame, so you would not have errors. The object would always be in the area.

avatar image Hydroque · May 28, 2013 at 05:40 PM 0
Share

So I have this block that moves down a non-linear path. If I were to use this method estimating the distance to the block would be irrational. Example would be the blocks line of symmetry. One block could be the exact same distance from a block, but on different ends. I was think about making a 'time' variable that dictates how long a part has been ingame to see if it needs shot at. How would you tackle it?

avatar image robertbu · May 28, 2013 at 11:21 PM 0
Share

You are asking new questions as comments to an existing questions. We try to keep it to a single issue per question. Also I don't understand what you are asking here. You will need more detail and perhaps a drawing. If you original question is answered, click the checkmark next to the best answer to close it out. Feel open a new question for this next issue.

avatar image Hydroque · May 29, 2013 at 12:23 AM 0
Share

I took about 3 or 4 hours of my day with this single function (idiot me) to figure out how everything works with Physics.OverlapSphere(). Thank you for the support, I figured out a excellent way to code my product and i have succeeded. Thanks for the support, now i'm going to battle my other problem. FLAC$$anonymous$$ CANNONS! I have a cannon that shoots on a 1 seconds delay, but multiple times haha.

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

13 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

Related Questions

Make an object destroy the object it is touching? 2 Answers

How can i make my scene restart once my character has collided with another object? 2 Answers

Move object to raycast point. 3 Answers

Collision between objects 2 Answers

Adding sound javascript in unity2d 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