Collision Detection (Under the hood)

Hello, just a few questions to get a better understanding on how collision detection works.

  1. When using the global collision handling (with Runtime), upon a collision between physics bodies (let’s call them ‘x1’ and ‘x2’), am I correct to assume that the handler will be called once with either :

Scenario 1: event.object1 == x1 and event.object2 == x2

      OR

Scenario 2: event.object2 == x2 and event.object1 == x1

And it will not call the handler twice with both scenarios. Is this correct?

  1. Assuming it is, what determines the order of the event objects? In other words, why would Scenario 1 occur as opposed to Scenario 2 or vice versa? For example, could it have something to do with when an object is created? or where on the display hierarchy they are? OR is it arbitrary?

  2. The Collision Detection Documentation states: “If you need to modify /create an object as a result of a collision, your collision handler should set a flag or add a time delay so the change can occur in the next application cycle or later”. Is there a particular set of modifications that this refers to? For example, if I understand correctly, this applies for the isBodyActive property. Does it similarly apply for all other physicsBody properties? What about properties that are not related to physics? Knowing this type of information would help me better understand and plan for the cases in which I should use a time delay (as opposed to making changes to an object within the handler).

Thank you very much for your time and have a nice day!

Hi @jhow,

1&2) I haven’t done any specific testing on this (I usually use local collision handlers, not global). It may have to do with the order in which physics bodies are added. In any case, if you “return true” in the handler, it won’t call the event twice.

  1. I may try to get a list compiled (and documented) on which actions require a time delay, and which don’t, since this question has come up before.

Thanks,

Brent

Hi @jhow,

1&2) I haven’t done any specific testing on this (I usually use local collision handlers, not global). It may have to do with the order in which physics bodies are added. In any case, if you “return true” in the handler, it won’t call the event twice.

  1. I may try to get a list compiled (and documented) on which actions require a time delay, and which don’t, since this question has come up before.

Thanks,

Brent