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 Matt 15 · Nov 16, 2010 at 01:49 PM · collisionrandomspawnontriggerenteroncollisionenter

Collision, but then only affect ONE of the gameObjects?

[using iOS]

-- Hey everyone, I have a situation that i could use come guidance with. I need to randomly spawn some cubes in a predetermined space (like a 4x3 grid). While doing this, I some times get spawns at the same location. I tried testing for OnCollisionEnter, and then destroy the object, and trying again, only... that will destroy BOTH objects, since they get a "true" when they get their signal that they are colliding.

My question is, is there a way to ONLY do execute code for ONE of the objects, or two, a better way to do something like this in general. (like having each spawn point have a bool var that get's flipped to true if it ever spawns a cube at it's spot?)

Thanks in advance!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Proclyon · Nov 16, 2010 at 02:16 PM

Here's my answer based on my interpretation of your question (with which I could use some help in the form of further explanation of your goals and methods)

Collisions happen at the same time. You can not discriminate who was first or last without using a time variable on the spawning of the object. Use a time to determine this and destroy the first or last based on that timer.

You could also random who dies by creating a random number between 0 and 1 and see if this object dies but then you would have to tell the other block to ignore the very same command of course so it would need to talk to the other object and pass that message.

You could also make a spawn system handle it, fill a 2D array with objects randomly without letting any overrides occur (so check for null), untill the array is full. You may want to not make a 10000 size 2D array for that with this random type of sorting though. Takes quite some time if it get's to huge.

Well with more info maybe I can give you a better answer ;)

Good luck in any case :)

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
avatar image
0

Answer by Vajoiner · Jan 16, 2011 at 12:27 AM

to achieve this i created a do/while loop that randomly placed an object on a grid, checked an array of earlier placed objects to see if it was within the objects h/w plus the array objects h/w and if not, then finally place the object and add it to the array so i can place the next object. it was fun to figure that out.

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

No one has followed this question yet.

Related Questions

2 objects collide, need to destroy one 2 Answers

Have bullets be destroyed when they collide with ANY collider 0 Answers

OnTriggerEnter with exact spot of collision 2 Answers

How to detect collision without OnCollisionEnter or OnTriggerEnter? 1 Answer

Spawn Random Item On Trigger Enter 2 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