How to change characters physics in a physics world?

Hi,

I am having a flying character in my physicsworld. Within a stage I want to change hes physics parameters, but I cant figure out - how to?

First I am adding him to the world:

 physics.addBody(player,{friction=2, bounce = .9})  

Then later on I want to remove him from the Physics engine, and resign him but that doesnt work?

 physics.removeBody( player )  
 physics.addBody(player,{density=2,friction=.9, bounce = .1})  

Any suggestion on how to solve this?

Best regards, Joakim [import]uid: 81188 topic_id: 15970 reply_id: 315970[/import]

Hi.

Try removing the whole player and re-creating it.

[code]

local player

player = display.newImage(“player.png”)
physics.addBody(player, “dynamic”, {isSensor = false}

–remove it when needed
player:removeSelf()

–Recreate it when needed
player = display.newImage(“player.png”)
physics.addBody(player, “dynamic”, {isSensor = false}
[/code] [import]uid: 84637 topic_id: 15970 reply_id: 59197[/import]

Yeah Danny is right, as i’ve done this for my game.
I’ll add in some remarks which i found out throughout my experience while doing this.

[code]
local xsave = 0; – blank x variable.
local ysave = 0; – blank y variable.

local player – Predeclaring your character, this allows recreated one to share his variables.

player = display.newImage(“player.png”)
physics.addBody(player, “dynamic”, {isSensor = false}

–remove it when needed
xsave = player.x; – I did this because i wanted the newly spawned player
ysave = player.y; – to stay in the same place as the old one. Optional.
player:removeSelf()

–Recreate it when needed
player = display.newImage(“player.png”)
– Newly spawned one’s x and y co’ords to be savex and savey.
physics.addBody(player, “dynamic”, {isSensor = false}
–If your character is part of any groups i needed to redo localGroup:insert(player) in order to fix an issue i had.)[/code] [import]uid: 91798 topic_id: 15970 reply_id: 59200[/import]

A way you might implement that is to have a separate table store all the character’s information (such as x/y position, etc.) so that when you remove it and re-create, you can restore it to it’s original state (from the user’s perspective, nothing really changes … but it can then have a different physics body). [import]uid: 52430 topic_id: 15970 reply_id: 59226[/import]

Thanks all for your replies! I will try this and i am sure that it would work 100%!

Thanks, Joakim [import]uid: 81188 topic_id: 15970 reply_id: 59302[/import]