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 /
  • Help Room /
avatar image
1
Question by Dragonsnare0 · Oct 21, 2015 at 04:47 AM · javascriptrigidbodycollider

2 Rigidbodies at rest collision detection issue

So here's my issue

I need to detect when 2 or possibly more rigidbodies are touching so when I click on them they destroy based on their IDs

My code works just fine if I click on them during the time of interaction before they come to a rest, but once they stop moving and enter a rest state the contact is no longer being recognized.

Here's the code and mind that I have tried changing it to a OnCollisionStay with no avail.

 function OnCollisionEnter(col:Collision) {
     myHit = new Array();
     for (var i=0;i<myStage.bubs.length;i++) {
     var goodFind:boolean =true;
     if (myStage.bubs[i]==null) {
         goodFind=false;
     }
     if (goodFind) {
     var goodHit:boolean =false;
     var thisBub:BlockControl;
     thisBub = myStage.bubs[i].GetComponent(BlockControl);
         if (thisBub.myType==myType) {
             if (col.gameObject == myStage.bubs[i]) {
                 goodHit=true;
                 myHit.push(i);
             }
         }
         }
     }
 }

the myHit array is just storing positions in an array of the other gameobjects to know which to destroy

the myType is just to make sure they are matching colors.

I've been at this for a while and am probably just not seeing something simple and stupid any help is welcome.

Thanks in advance,

-Ron

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 rageingnonsense · Oct 21, 2015 at 10:35 PM 0
Share

Try maintaining a list of objects that can be destroyed OUTSIDE of this method. Use OnCollisionEnter() to do nothign more but ad to this list if it should be in there (and remove it via OnCollisionExist()).

Then, when you click on one of your objects, check to see if it is in the list. If so; destroy it.

What you are doing now is populating an array that will cease to exist once the function leaves scope.

1 Reply

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

Answer by The-Little-Guy · Oct 22, 2015 at 01:30 AM

Once an object has no more velocity, the rigidbody falls asleep. You should try and keep it awake using WakeUp() you can also check to see if it IsSleeping()

How you keep it awake is up to you. I think the best place to do this would be on OnCollisionStay

 function OnCollisionStay(other : Collision) {
     other.GetComponent(Rigidbody).WakeUp();
 }

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 Dragonsnare0 · Oct 23, 2015 at 02:30 AM 0
Share

Good Idea I. I'm also going to have it populate the myHit array and not wipe it everyframe just have it splice things out as the contact exits but keep them on a stay.

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

36 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 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

Why are the 2D colliders not working? 0 Answers

why my object pass through 0 Answers

Character doesn't collide with the floor. 0 Answers

Simplest Box Collider Question. 2 Answers

Adding collisions to a custom character controller? 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