preCollision fires after Collision 'began' phase

I am trying to do what many people do, and that is make a character be able to jump through a platform and land on its top. I understand that using the preCollision event along with event.contact.isEnabled is the way to do this. 

However, when simulating the game, the ‘began’ phase of the collision fires, then a bunch of preCollision events (which I expected because the documentation said it can be noisy), followed by the ‘end’ collision event.

A sample output is:

END ( jumped off ground)

BEGIN (hit platform)

PRE (platform pre-collision events)

PRE

PRE

PRE

PRE

PRE

PRE

PRE

PRE

PRE

PRE

PRE

PRE

END (leave platform)

My code (the important parts at least):

[lua]

– run for each colision event

local function onCol (event)

     – if any collision object is nil, then return

     if (event.object1 == nil or event.object2 == nil) then

          return

     end

     – set collision object (not player) as obj2

     local objCol = event.object2

     if (event.object2 == bound) then

          objCol = event.object1

     end

     – see what was hit

     if ( event.phase == ‘began’) then

          print(‘BEGIN’)

     elseif (event.phase == ‘ended’ and objCol.name == ‘rec’) then

          print(‘END’)

     end

end

– prevent player from colliding with platforms bases

local function preCollision(event)

     local colObj = event.other

     if (colObj.colType == ‘pass’ and colObj.active == false) then

          print(‘PRE’)

     end

end

– listeners

listen( ‘preCollision’, preCollision, bound)

listen( ‘collision’, onCol)[/lua]

Could this be a problem with Corona? I read on older forums that it was a problem in the past but that it was resolved in one of the builds.

Hi @shepherd.potatoes.brett3,

In reality, the pre-collisions are occurring before the normal collisions. It’s just that the print() into the Terminal cannot accurately state exactly the order in which this all happens internally, because there is so much going on at the same time… in fact, pre-collisions in themselves will fire many, many times internally, and that doesn’t even take into account the normal collisions.

The most important thing to note is whether your simulation is working and that the character is passing through the platform by disabling the PhysicsContact for the collision. If that is working, then I wouldn’t worry too much about the “order of things” in this case.

Best regards,

Brent

Could this be a problem with Corona? I read on older forums that it was a problem in the past but that it was resolved in one of the builds.

Hi @shepherd.potatoes.brett3,

In reality, the pre-collisions are occurring before the normal collisions. It’s just that the print() into the Terminal cannot accurately state exactly the order in which this all happens internally, because there is so much going on at the same time… in fact, pre-collisions in themselves will fire many, many times internally, and that doesn’t even take into account the normal collisions.

The most important thing to note is whether your simulation is working and that the character is passing through the platform by disabling the PhysicsContact for the collision. If that is working, then I wouldn’t worry too much about the “order of things” in this case.

Best regards,

Brent