I have not test this but here is what I will do, so hope it helps:
- First you will have to use the collision categories for your objects (see http://developer.anscamobile.com/content/game-edition-collision-detection) So you will have two filters for your main jumper character and other category filter for all the platforms.
For example:
local PlataformeCollisionFilter = { categoryBits = 1, maskBits = 1 }
— platform only collides with objects with category bit equal to 1
local JumperHallowCollideFilter = { categoryBits = 2, maskBits = 2 }
— jumper will collide only with objects category 2 only
local JumperCollideFilter = { categoryBits = 2, maskBits = 3 }
— jumper will collide only with objects category 1 and 2
-
When creating the objects (jumper and platforms) add a name to the object:
plataform.myName = “plataform”
jumper.myName= “jumper”
-
Use the “preCollision” event to detect when a collision is about to happen. The preCollision event will give you the two objects that will be collide.
-
The “preCollision” event will give you the two objects that will collide. So you can check their names to see if one is the jumper and the other is the platform (or viceversa) (this is only if you have more objects that will collide with the jumper like bonus objects or coins etc.
local function onPreCollision( event )
if ( event.phase == “began” ) then
if (event.object1.myName == “platform” and event.object2.myName==“jumper” ) then
— do here the magic with object 1
end
if (event.object1.myName == “jumper” and event.object2.myName==“platform” )) then
— do here the magic with object 2
end
end
end
5) Now you will only need to identify the platform object. With this object you will get his linear velocity x,y = event.object1:getLinearVelocity()
-
Check the value of y . If y is >0 is going down if y<0 is going up (or viceversa dont remember which is up or down but you try it)
-
If you detect that the y points up that means that the jumper is going up and you will change the jumper collision filter to JumperHallowCollideFilter and if it’s going down you will change it to local JumperCollideFilter
-
The collision event will trigger after the preCollision so when it does your jumper will collide with the platform or pass thru it.
[import]uid: 9975 topic_id: 3996 reply_id: 12214[/import]