Help Collision and preCollision

HI I need a help about my game.

I wish that when my character jump pass through bar but would rank bar just above the height of the character super bar’s height

thank you !

[code]
lol.preCollision = function(self, event)

if self.name == “character” and event.other.name == “bar” then
bar.isSensor = true
end

end

local function onCollision(event)

if character.y < bar.y and event.object2.name == “character” and event.object1.name == “bar” then
bar.isSensor = false
else
bar.isSensor = true
end

end

Runtime:addEventListener( “collision”, onCollision )
lol:addEventListener(“preCollision”, lol)
[/code] [import]uid: 47941 topic_id: 32786 reply_id: 332786[/import]

this might be of some help:

http://docs.coronalabs.com/api/event/preCollision/index.html :
“In older versions of Box2D, you could set the isSensor property in the middle of a collision, e.g. in preCollision, to achieve pass-through objects. You can no longer do this.
Instead, you must use set disable the contact point of the collision. See example in event.contact.”

-> http://docs.coronalabs.com/api/event/preCollision/contact.html [import]uid: 11133 topic_id: 32786 reply_id: 130421[/import]

this might be of some help:

http://docs.coronalabs.com/api/event/preCollision/index.html :
“In older versions of Box2D, you could set the isSensor property in the middle of a collision, e.g. in preCollision, to achieve pass-through objects. You can no longer do this.
Instead, you must use set disable the contact point of the collision. See example in event.contact.”

-> http://docs.coronalabs.com/api/event/preCollision/contact.html [import]uid: 11133 topic_id: 32786 reply_id: 130421[/import]

thank you so much, i’ve used this function:

function box:preCollision( event )  
 local platform = event.other  
 if platform.myName == "platform1" then  
 -- Let box pass through platform 1  
 event.contact.isEnabled = false  
 print( "preCollision", platform.myName )  
 end  
end  
box:addEventListener( "preCollision" )  

thanks again ! [import]uid: 47941 topic_id: 32786 reply_id: 130450[/import]

thank you so much, i’ve used this function:

function box:preCollision( event )  
 local platform = event.other  
 if platform.myName == "platform1" then  
 -- Let box pass through platform 1  
 event.contact.isEnabled = false  
 print( "preCollision", platform.myName )  
 end  
end  
box:addEventListener( "preCollision" )  

thanks again ! [import]uid: 47941 topic_id: 32786 reply_id: 130450[/import]

@gaarathebest_94,

Are you thinking of one-way platforms?

See this short video. (From SSKCorona Sampler).

If so, here is the code that does the work:

[lua]local Corona_build = tonumber(system.getInfo( “build” ))

local function onCollision( self, event )
if(event.phase == “ended”) then
if(Corona_build < 2012.890 ) then
event.target.isSensor = false --(for versions before 890)
else
event.contact.isEnabled = true --(for versions 890 and after)
end
end
return true
end

local function onPreCollision( self, event )
if(event.target.y < event.other.y) then
if(Corona_build < 2012.890 ) then
event.target.isSensor = true --(for versions before 890)
else
event.contact.isEnabled = false --(for versions 890 and after)
end
else
if(Corona_build < 2012.890 ) then
event.target.isSensor = false --(for versions before 890)
else
event.contact.isEnabled = true --(for versions 890 and after)
end
end
return true
end

– …
createPlayer = function ( x, y, size )
player = ssk.display.rect( layers.content, centerX, screenBot-20-size,
{ size = size, myName = “thePlayer”, fill = _BLUE_,
stroke = _WHITE_, strokeWidth = 2, },
{ isFixedRotation = false, friction = 1.0, bounce = 0.0,
linearDamping=0.45, bodyType = “dynamic”,
colliderName = “player”, calculator= myCC } )

return player
end

createPlatform = function ( x, y, width, height )
local platform = ssk.display.rect( layers.content, x, y,
{ width = width, height = height, myName = “aPlatform”,
fill = _YELLOW_, stroke = _WHITE_, strokeWidth = 2, },
{ isFixedRotation = false, friction = 0.0, bounce = 0.0,
linearDamping=0.45, bodyType = “static”,
colliderName = “platform”, calculator= myCC } )

platform.collision = onCollision
platform.preCollision = onPreCollision

platform:addEventListener( “preCollision”, platform )
platform:addEventListener( “collision”, platform )

return platform
end[/lua]

Note: There are some calls the to the SSKCorona library in here, but what you really want is the onCollision()/onPreCollision() code.

Cheers,

Ed [import]uid: 110228 topic_id: 32786 reply_id: 130469[/import]

@gaarathebest_94,

Are you thinking of one-way platforms?

See this short video. (From SSKCorona Sampler).

If so, here is the code that does the work:

[lua]local Corona_build = tonumber(system.getInfo( “build” ))

local function onCollision( self, event )
if(event.phase == “ended”) then
if(Corona_build < 2012.890 ) then
event.target.isSensor = false --(for versions before 890)
else
event.contact.isEnabled = true --(for versions 890 and after)
end
end
return true
end

local function onPreCollision( self, event )
if(event.target.y < event.other.y) then
if(Corona_build < 2012.890 ) then
event.target.isSensor = true --(for versions before 890)
else
event.contact.isEnabled = false --(for versions 890 and after)
end
else
if(Corona_build < 2012.890 ) then
event.target.isSensor = false --(for versions before 890)
else
event.contact.isEnabled = true --(for versions 890 and after)
end
end
return true
end

– …
createPlayer = function ( x, y, size )
player = ssk.display.rect( layers.content, centerX, screenBot-20-size,
{ size = size, myName = “thePlayer”, fill = _BLUE_,
stroke = _WHITE_, strokeWidth = 2, },
{ isFixedRotation = false, friction = 1.0, bounce = 0.0,
linearDamping=0.45, bodyType = “dynamic”,
colliderName = “player”, calculator= myCC } )

return player
end

createPlatform = function ( x, y, width, height )
local platform = ssk.display.rect( layers.content, x, y,
{ width = width, height = height, myName = “aPlatform”,
fill = _YELLOW_, stroke = _WHITE_, strokeWidth = 2, },
{ isFixedRotation = false, friction = 0.0, bounce = 0.0,
linearDamping=0.45, bodyType = “static”,
colliderName = “platform”, calculator= myCC } )

platform.collision = onCollision
platform.preCollision = onPreCollision

platform:addEventListener( “preCollision”, platform )
platform:addEventListener( “collision”, platform )

return platform
end[/lua]

Note: There are some calls the to the SSKCorona library in here, but what you really want is the onCollision()/onPreCollision() code.

Cheers,

Ed [import]uid: 110228 topic_id: 32786 reply_id: 130469[/import]

thank’s emaurina ! :smiley: [import]uid: 47941 topic_id: 32786 reply_id: 130559[/import]

thank’s emaurina ! :smiley: [import]uid: 47941 topic_id: 32786 reply_id: 130559[/import]