Holes in the ground for a physics body to fall through

There might be an easier and more intuitive way to do this, but…

I am trying to make a ground, say with

 local ground = display.newRect(0,150,320,10)  
 ground:setFillRect(255,255,255)  
  
 physics.addBody(ground, "static", { friction=0.5, bounce=0.0 })  

Now that is one solid piece of ground and any “body” that will interact with this will stop instantly (unless it has a bounce factor)

now I want to create a hole in the ground, a trigger if you may, that will make the body fall through, I tried to use collisions by adding a hole in the ground like

 local hole = display.newRect(0,149,320,11) -- 1 pixel above and covers the ground  
 hole:setFillColor(0,0,0)  

now on the onCollision event I did manage to detect the collision between the object and the hole, but how do I make it fall through?? (cheat and position it down by 10 pixels so that it just falls?)

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3051 reply_id: 303051[/import]

If I add the code player.y = player.y + 15
the emulator/simulator crashes, it said something about assert being false and something locked. [import]uid: 3826 topic_id: 3051 reply_id: 8918[/import]

You need to assign more than one collision object to the ground. That way you can build 2 pieces of ground with a gap in the middle.

Check the docs for how to do that. [import]uid: 5354 topic_id: 3051 reply_id: 8939[/import]

Thank Matthew, so what you are suggesting are two pieces of the platform with a hole to fall through, right?
I need to scroll this *ground* like a moving platform so it was easier to move the hole than two largish platforms.

The object collides with the hole, how can I re position the object to a new position without the simulator crashing? [import]uid: 3826 topic_id: 3051 reply_id: 8940[/import]

You can, one image, draw multiple collision boundaries with the “Complex body construction”. If the hole is fixed in a point in the background then I would stick the whole thing in a group and scroll the group. But its hard to tell without seeing your setup.

But I personally would attach the collision boundaries to a graphic representing the ground and obviously the hole would be a part of the graphic. I would also have a normal tile for the ground without the hole. I would then place the holes along the normal ground at what ever intervals and do a bit of code to cal distance between holes and draw the remaining ground collision boundaries.

You can remove the physics from the body, change to static or kinetic from dynamic so you can move it I think. Ive not tried that yet but one of the examples, with platforms I think, shows how to do that. [import]uid: 5354 topic_id: 3051 reply_id: 8941[/import]

Hi Matthew,
thanks for the reply. Would it help if I said I was trying to make something like Nebulus. That is a very good example that takes a lot of things into account and is easier to make in Corona than plain objective-C or Cocoa-2D.

Now, it would be unfair on my part to expect the whole thing translated for me, but if you could help with some kind of source code to try, it would be really helpful.

I have read your comment about using collision boundaries, honestly, I have not understood that as yet, so am still trying to re-read to get that clear. If you have any code or links to code that demonstrate how to…, would be helpful

thanks,
cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3051 reply_id: 8942[/import]

The old tower climbing game, I used to love that on the Amiga, was called something else though I think…

If so then there is possibly a bunch of ways of doing it. The ground is basically 7 blocks, 5 that span the tower and 2 little ones, one either side to give the perspective.

Ok to do this I would still use groups / sprites.

I would setup a 1 block sprite, that has the 7 frames of animation for the 7 positions that the tower block could be in. This block would be 1 collision boundary the width of the standard block, the one in the centre of the tower.

I would also setup a blank block the same way without the collision boundary.

I would do this firstly so I can setup a level with an array of sorts, { ‘block’ , ‘block’ , ‘block’ , ‘block’ , ‘blank’ } etc…

Then to move the blocks I would just replace the current 7 with the array position + 1 and it would draw the next sequence. Animation would be a little harder but sprites would take care of that.

That way as you position the blocks according to the array it would be automatic if the hole appeared as the object for that block would not contain a collision element.
What I usually do in these cases is setup a prototype and keep refining it until I get to a working level. [import]uid: 5354 topic_id: 3051 reply_id: 8943[/import]