Body falls thru floor

Hi. Sorry for double post. Didn’t know about the subscribers forum!

I have a strange problem.
If I create a dynamic object, add it to the physics and then place it on a static floor.
If I then change it’s bodyType to static and back to dynamic it “falls” a little “into” the floor before moving up again.
It moves a little more each time and finaly it falls thru!?

I’m kind of new to the Corona SDK, but I have seen similar posts regarding similar problems (same problem but when touching objects)

It seems the physics engine uses time to “grap” the body after the bodyType change??

Frode [import]uid: 18310 topic_id: 8459 reply_id: 308459[/import]

This appears to be a bug in the Box2D engine.

http://code.google.com/p/box2d/issues/detail?id=169
http://box2d.org/forum/viewtopic.php?f=8&t=6010

A comment in the box2d thread provides this workaround: set your body’s active flag to false when you change the body type. Then on the next update, set it back to true again.

local physics = require("physics")physics.start()physics.setDrawMode("hybrid")local rect = display.newRect( display.contentCenterX, 400, 100, 100 )physics.addBody(rect, "dynamic")local floor = display.newRect( 0, 480, 320, 1 )physics.addBody(floor, "static")function changeMode( event ) if event.phase == "began" then local type = event.target.bodyType if type == "dynamic" then event.target.bodyType = "static" event.target.isBodyActive= false else event.target.bodyType = "dynamic" event.target.isBodyActive= true end endendrect:addEventListener("touch", changeMode)[/code]Tim [import]uid: 8196 topic_id: 8459 reply_id: 30448[/import]

Hi.
Greate thank you for the reply!
I’ll test as soon as i’m back from my trip.

Frode [import]uid: 18310 topic_id: 8459 reply_id: 32093[/import]