#Getting collisions as list at a specific time

1 messages · Page 1 of 1 (latest)

hard grove
#

Hi, I have Y method which I will execute when X happens, when the Y method get's executed, I want to get all the collisions happening at the moment that the Y method got executed. How can I do that? What are my alternatives if I am not able to do that

oak fern
#

are they both colliders?

#

like does the object that is colliding the other object have a Box Collider... and are you using 2D or 3D?

hard grove
#

yes both has colliders, it's 3d

oak fern
#

ok

#

i haven't tested it, but I think if you do the following:

int collisions = 0;

void OnCollisionEnter(Collision collision) {
        collisions += 1;
}

void OnCollisionExit(Collision other) {
        collisions -= 1;
}

then you just check collisions and that would be the answer

hard grove
#

hmm

#

yeah actually I haven't thinked about OnCollisionExit, this solution looks fine

#

let me try that

oak fern
#

did it work? if so, delete the thread...

hard grove
#

sorry forgot to make a feedback since it got interrupted with some other stuff

#

it did work, I had to change the OnCollision stuff to OnTrigger in my case though

#

thanks for the idea and solution