what's the best way to swap physic bodies (or their properties) ?

Hello Everybody.

i’m currently making a little sidescrolling jump and run game.
the “hero” should have different physical properties on user interaction.
in the game that looks like this:
when just touching the move interface (move buttons) it walks, driven by a motor joint with a high friction and density.
when touching the “slide” button in addition it should behave like sliding, or better rolling, on ice.

if the example above is confusing think of that:
normal behaviour is like super mario, if an additional button is touched the behaviour shall switch from a mario like behaviour to a tinywings like behaviour.

now my thoughts on implementing that:
a) modifying the densitiy and friction, but how i found out, that’s just possible within the addBody function, and can just be changed be readding the body, what could be very bad for the performance.

b) having 2 hero setups, and swapping them on user interaction. means, moving the “walking” hero out of the scrolling gameworld displaygroup, and just put it on a fixed position out of the screen. while putting the “sliding” hero into the gameworld displaygroup on the former coordinates of the “walking” hero. and vice versa.

both do sound complicated to me, so i was wondering if there is any better way to do this.
or if you have any suggestions.
on b) i wish i could just disable the one object, like setting isVisible to false, just for the physics bodies. without having to put it offscreen.
at the moment, i feel a little bit lost, what way i should go, and what won’t kill the performance.

cheers,
michael [import]uid: 11133 topic_id: 32861 reply_id: 332861[/import]

Personally I’d try removing and readding the body; I don’t believe doing this on one body will cause any big performance issues. The two hero option is also a possibility; I’d experiment. If targeting Android I’d test both on a lower end device, though iOS I can’t imagine any current device would have a real issue with either approach.

Edit: If you are constantly needing to swap out it *might* make more sense to have two bodies you switch the positions of rather than constant, frequent adding and removing. [import]uid: 52491 topic_id: 32861 reply_id: 130767[/import]

Hey peach pellen,
thanks a lot for your reply and your opinion on the “issue”, it’s very good for me to know that i’m not in a completely wrong direction with my ideas of handling it.

the swap happens pretty often, so i decided to have the two bodies.
for now i’m only focussing on iphone developement, good to know that the current devices won’t have problems with that. an android version would be an option if the game will sell not too bad in the appstore :wink:

thanks for your tutorials by the way, they helped me a lot to get started. and the pay with a tweet method is a really good thing, i used that too for some of my iphone wallpaper downloads. [import]uid: 11133 topic_id: 32861 reply_id: 130786[/import]

Personally I’d try removing and readding the body; I don’t believe doing this on one body will cause any big performance issues. The two hero option is also a possibility; I’d experiment. If targeting Android I’d test both on a lower end device, though iOS I can’t imagine any current device would have a real issue with either approach.

Edit: If you are constantly needing to swap out it *might* make more sense to have two bodies you switch the positions of rather than constant, frequent adding and removing. [import]uid: 52491 topic_id: 32861 reply_id: 130767[/import]

Hey, I’ve had some success with adding a function onto my hero’s display group which takes the name of the physics value to change and then decides itself whether to remove and re-add the physics body or just modify the existing value (depending on the API allowances.) As Peach rightly points out, this probably comes with a performance deficit which on lower end devices might be an unacceptable penalty.

For the other option, you don’t need to move the hero out of the scene or anything annoying like that; Just set its isBodyActive to false (stops it being considered a physics object) and set its isVisible to value (makes it invisible) - then just switch the other version of your hero to true for those values.

Having said all of the above, you don’t really have a choice if you don’t know what the target values (which can only be set when calling addBody) are going to be - you would have to re-add the body.

Given that it looks like you know what the two states are, I’d go for the two versions solution, because there performance hit is lower, IMHO.

Test, test, test, then test again. [import]uid: 8271 topic_id: 32861 reply_id: 130789[/import]

Hey peach pellen,
thanks a lot for your reply and your opinion on the “issue”, it’s very good for me to know that i’m not in a completely wrong direction with my ideas of handling it.

the swap happens pretty often, so i decided to have the two bodies.
for now i’m only focussing on iphone developement, good to know that the current devices won’t have problems with that. an android version would be an option if the game will sell not too bad in the appstore :wink:

thanks for your tutorials by the way, they helped me a lot to get started. and the pay with a tweet method is a really good thing, i used that too for some of my iphone wallpaper downloads. [import]uid: 11133 topic_id: 32861 reply_id: 130786[/import]

Hey, I’ve had some success with adding a function onto my hero’s display group which takes the name of the physics value to change and then decides itself whether to remove and re-add the physics body or just modify the existing value (depending on the API allowances.) As Peach rightly points out, this probably comes with a performance deficit which on lower end devices might be an unacceptable penalty.

For the other option, you don’t need to move the hero out of the scene or anything annoying like that; Just set its isBodyActive to false (stops it being considered a physics object) and set its isVisible to value (makes it invisible) - then just switch the other version of your hero to true for those values.

Having said all of the above, you don’t really have a choice if you don’t know what the target values (which can only be set when calling addBody) are going to be - you would have to re-add the body.

Given that it looks like you know what the two states are, I’d go for the two versions solution, because there performance hit is lower, IMHO.

Test, test, test, then test again. [import]uid: 8271 topic_id: 32861 reply_id: 130789[/import]

"
For the other option, you don’t need to move the hero out of the scene or anything annoying like that; Just set its isBodyActive to false (stops it being considered a physics object) and set its isVisible to value (makes it invisible) - then just switch the other version of your hero to true for those values.
"
very nice, i will definitely give it a try.
thank you very much. [import]uid: 11133 topic_id: 32861 reply_id: 131133[/import]

"
For the other option, you don’t need to move the hero out of the scene or anything annoying like that; Just set its isBodyActive to false (stops it being considered a physics object) and set its isVisible to value (makes it invisible) - then just switch the other version of your hero to true for those values.
"
very nice, i will definitely give it a try.
thank you very much. [import]uid: 11133 topic_id: 32861 reply_id: 131133[/import]