How to remove physic body ?

Hi there,
In corona game edition, we can add new physic body by call physics.addbody.

 instance = movieclip.newAnim{ "GFX/ingame/normal\_rock.png", "GFX/ingame/normal\_rock\_break1.png", "GFX/ingame/normal\_rock\_break2.png" }  
  
 physics.addBody( instance, { density=5.0, friction=1.0,bounce=0.4 } )  
 instance.myName = "block4test"  

But in my game, I need to remove physic body from the instance.
I’ve tried both instance.remove(1) and instance.remove(2) but still have no lucky.
There is no physics.removeBody method, too.

Please tell me, how to remove an existed physic body from an object (in order to turn it become a normal sprite)

Thank you.
[import]uid: 9190 topic_id: 3081 reply_id: 303081[/import]

Hey Khan,

This should help you out - http://developer.anscamobile.com/content/game-edition-physics-bodies#Destroying_bodies

// red. [import]uid: 7143 topic_id: 3081 reply_id: 9036[/import]

Hi Red,

I actually had the same question as Khahn, and found the same documentation you link to. However, the question is, how might one go about removing only the physics body attached to an object, not the entire object?

One possible “solution” is to change the body type to kinematic, which in theory makes it immune to interacting with other physical objects. However, I’m not sure that always works properly… in my initial test, changing one body from dynamic to kinematic did accomplish that, but the bodies still reacted physically with each other. I might have done something wrong, so I’ll have to go back and check the “drag boxes” sample in the Sample Code folder.

Regardless, It would be awesome to have a function like physics.removeBody in addition to physics.addBody. ANSCA, please add this to your roadmap! :slight_smile: Additionally, I would enjoy a method to dynamically change Collision Filter groups for any object… those can be declared when the physics body is created, but I don’t think they can be changed during runtime, i.e. when a collision occurs or a button is pressed or whatever.

Brent
[import]uid: 9747 topic_id: 3081 reply_id: 9051[/import]

Change it to “static” or maybe
Body.isBodyActive=false
I haven’t tried it but may work [import]uid: 7911 topic_id: 3081 reply_id: 9059[/import]

Thanks jstrahan, I’ll try that (maybe I already did, can’t remember). When I needed to remove a physics body recently, my purpose was more “would be cool visually, but not really necessary for the gameplay”, so I put the issue on the shelf until later. I’ll try it again someday and I’ll probably find a solution. :slight_smile:
[import]uid: 9747 topic_id: 3081 reply_id: 9061[/import]

Welcome
God I wish I was at home on corona instead of working
[import]uid: 7911 topic_id: 3081 reply_id: 9062[/import]

I filed an enhancement request for physics.removeBody() (case #1670). Thanks for the feedback. I’m not sure of a suitable workaround at the moment, but will investigate further.

It sounds like jstrahan’s suggestion of setting isBodyActive to false might work for you, depending on the scenario of course.

Tim [import]uid: 8196 topic_id: 3081 reply_id: 9068[/import]

Just a thought, and would much prefer physics.removeBody, but what if you added the physics body to a parent group. Later, when you want to take the body away, simply remove the image from the parent group, add it to the stage (or another group) and destroy the group with the body applied. Of course, a shape would need to be used when defining the shape of the physics body.

Just a thought, and I may have mis-thought the workings of groups…

matt. [import]uid: 8271 topic_id: 3081 reply_id: 14783[/import]

Hi Ansca!

any progress on case #1670?

this looks like feature I am looking for - to recreate body for display object so to change its properties (like shape/scale).

AFAIK Box2D does not allow changing that so you need to destroy and create new body. That said - physics.removeBody() looks like something promising. Another way would be to change behaviour of physics.addBody() if called on already a physics object (so old Box2D body gets destroyed and new one is created).

This would also allow us to workaround some issues reported on sprites/spritesheets.

Greetings,
~K.
[import]uid: 42082 topic_id: 3081 reply_id: 29184[/import]

If you set isBodyActive = false, you get the same effect as :removeBody() but the properties are still accessible and it won’t complain when you set things like x and y directly. [import]uid: 8271 topic_id: 3081 reply_id: 29191[/import]

x&y are properties of display object not physics ones.

unfortunately - even if you make body inactive you still cannot change its shape :frowning:

(changing shape might be needed if you eg. want to change scale of the object - I guess best if Ansca could make it transparent for us without the need to destroy/recreate b2body in lua…)

[edit]
OK, best if that’s not done transparently - it would not keep kinetic data of the object and would be really confusing…
[/edit] [import]uid: 42082 topic_id: 3081 reply_id: 29193[/import]

On October 2010, this case (1670) was filed.
Today is Jun 2011, 8 months after.
I dont see that case included.
Do you? [import]uid: 41639 topic_id: 3081 reply_id: 41289[/import]

did you guys tr doing myObject:removeSelf() and then just made a new graphic in the place were the physic body use to be so that it looks like it was the same graphic ?
that might help [import]uid: 23689 topic_id: 3081 reply_id: 42179[/import]

Bleeech !

found it. still unresolved. and it is like that because it is assigned to an engineer who no longer works with us.

!! OUCH ||
reassigned and opened to fix for next release.
c. [import]uid: 24 topic_id: 3081 reply_id: 42198[/import]

It would be good to have access to information of all the “cases”, date they were filed and estimated date they will be implemented.
That would serve a marketing for you and a way to push yourselves to have things done.
I wonder if there is any place where we could post our “wish lists” and check if they would be implemented or not and maybe the reason?
[import]uid: 41639 topic_id: 3081 reply_id: 42204[/import]