@CSIV2013to2014
Sorry for late answer.
Uhm…I wouldn’t recommend playing around with physics during collisions. Adding physics bodies, turning physics on/ off and all that can ruin the performance of your game.
I’m not sure if it’s possible to do that…right now I can’t think of anything to access layer properties within main.lua
Correct me if I’m wrong please.
You could however detect if your character (or something) collides with tiles, and it’s possible to detect if physics bodies collided vertically or horizontally.
If they collide horizontally (while moving over the X axis), let the character pass through the stairs. How to let him pass through the stairs?
I think it’s possible to do that by using collision—>event.contact
Haven’t tried using event.contact myself yet, but that’s probably what we’re looking for.
…yeah, they use event.contact for the same thing right here.
Ok, so how to detect if objects collide vertically or horiontally?
I came up with some code that can detect that…originally I used it for something in my game.
Anyways here’s the code:
--detects if the character hits a wall by its side or its top. function colision\_detect(event) if(event.object1.myName == "tile" and event.object2.myName == "character") then if(event.phase == "began") then if(event.object2.contentBounds.yMax \> event.object1.contentBounds.yMin) then print("collided horizontally") else print("collided vertically") end end end end Runtime:addEventListener("collision", collision\_detect)
It’s basically comparing character’s y value when collision happens.
The code that I wrote there only detects if collision happened on top of the tile or on side.
Doesn’t work if they collide on the bottom side of the tile.
You could use the same method to detect if the character hits the stairs with his head, so that he can pass through them from below.
…or IF they collide on top, let the character stand on the stairs ELSE make him pass through.
You will have to make some exceptions, if the character is already on the stairs…shouldn’t be a problem.
Hope this helps.