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]