[RESOLVED] Help for how to make a character jump through a platform?

I have been trying to figure this out how to how make a character jump through a platform. Every time I make the character jump through it does not become solid I read every description about collision. Read, read, and read found other forums but those did not help.

Can anyone please help this is how I have the code:

[code]

local fi = sprite.newSprite (heroset)
–local player = display.newImageRect(“Player.png”, 50, 50)
fi.x = 240
fi.y = 100
physics.addBody(fi, “dynamic” , { density = 10, isSensor = false})
game:insert(fi)

local plat = display.newRect(0,0, 100, 10)
plat.x = 330
plat.y = 220
plat.hit = “plat”
physics.addBody(plat, “static” , {isSensor = true})
game:insert(plat)

fi:addEventListener(“preCollision”, fi)
fi.preCollision = onLocalPreCollision
function fi:preCollision (event)
if event.other.hit == “plat” true then
physics.addBody(plat, “static” , {isSensor = false})
end
end[/code]
Ive been so stressed out about it. Can any please help thanks :slight_smile: [import]uid: 17058 topic_id: 26378 reply_id: 326378[/import]

Ok so I finally got it for anyone wanting to know How I got I got it this is how it looks

[code] local plat = display.newRect(0,0, 100, 10)
plat.x = 330
plat.y = 220
plat.hit = “plat”
physics.addBody(plat, “static” )
plat.isSensor = true

local fi = sprite.newSprite (heroset)
–local player = display.newImageRect(“Player.png”, 50, 50)
fi.x = 240
fi.y = 100
physics.addBody(fi, “dynamic” , { density = 10, isSensor = false})
game:insert(fi)

fi:addEventListener(“collision”, fi)
function fi:collision (event)
if event.phase == “ended” and event.other.hit == “plat” then
plat.isSensor = false
end
end[/code]

Just change how the character is displayed I used sprite. But you see the collision function that is the proper way to jump from the bottom up and stay on top :slight_smile:

If anyone has question feel free to post on this forum I will respond in less than 24 hours [import]uid: 17058 topic_id: 26378 reply_id: 106957[/import]

what am I missing, seems that a character moving up the screen would hit and cause a platform to switch to isSensor false. Seems this may not allow a character to pass through from below. [import]uid: 98652 topic_id: 26378 reply_id: 107762[/import]

@soggybag what is the exact problem your having? [import]uid: 17058 topic_id: 26378 reply_id: 107780[/import]

Here’s the code I used, built from your example above:

[lua]local physics = require( “physics” )
physics.start()

local game = display.newGroup()

local function make_platform()
local plat = display.newRect(0,0, 64, 10)
plat.hit = “plat”
physics.addBody( plat, “static” )
plat.isSensor = true

return plat
end

for p = 1, 5, 1 do
local plat = make_platform()
plat.x = p * 64
plat.y = math.random( 1, 6 ) * 64
– game:insert( plat )

local floor = make_platform()
floor.x = p * 64
floor.y = 7 * 64
end

local fi = display.newRect(0, 0, 32, 32) – sprite.newSprite (heroset)
fi:setFillColor( 255, 100, 20 )
–local player = display.newImageRect(“Player.png”, 50, 50)
fi.x = 240
fi.y = 100
physics.addBody(fi, “dynamic” , { density = 10, isSensor = false})
game:insert(fi)

fi:addEventListener( “collision”, fi )

function fi:collision( event )
if event.phase == “ended” and event.other.hit == “plat” then
event.other.isSensor = false
end
end[/lua]

I must have missed something. My character falls through all platforms. [import]uid: 98652 topic_id: 26378 reply_id: 107828[/import]

@soggybag I see the problem this code you have it like this

Your Below:

[code]

local fi = display.newRect(0, 0, 32, 32) – sprite.newSprite (heroset)
fi:setFillColor( 255, 100, 20 )
–local player = display.newImageRect(“Player.png”, 50, 50)
fi.x = 240
fi.y = 100
physics.addBody(fi, “dynamic” , { density = 10, isSensor = false})
game:insert(fi)[/code]

Try this instead Below:

local fi = display.newRect(0, 0, 32, 32) -- sprite.newSprite (heroset) fi:setFillColor( 255, 100, 20 ) --local player = display.newImageRect("Player.png", 50, 50) fi.x = 240 fi.y = 100 fi.isSensor = false physics.addBody(fi, "dynamic" , { density = 10}) game:insert(fi)

Sorry for delay tell me if it works [import]uid: 17058 topic_id: 26378 reply_id: 107933[/import]