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
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.
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();
}
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
Follow this Question
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