Is there a way to change physics body dynamically during animation? For example, I have a animated sprite that changes its shape drastically at the end of the animation or even midway through, how can I change the physics body to match its current state? Any advise very much appreciated. [import]uid: 70056 topic_id: 33248 reply_id: 333248[/import]
How are you doing the animations? Post the code and I’ll see if anything comes to mind. [import]uid: 181948 topic_id: 33248 reply_id: 132117[/import]
The way to do this is to remove physics from the object and then re-add them with a different shape. You will need to manually define the shape at each point (Or use a 3rd party tool to give you the right shape definitions). [import]uid: 135827 topic_id: 33248 reply_id: 132119[/import]
Thanks for the input, guys.
treb.stewart,
I am actually using SpriteHelper for the animation.
George18,
This seems pretty tedious especially if the animation changes often during the game and also if every frame has a different physics shape. [import]uid: 70056 topic_id: 33248 reply_id: 132133[/import]
@Falcon777 another way to do it would be to define all possible sets of physics boundaries on the object as separate shapes, then put each shape one into a different physics filter. In that case you will still probably need to add/remove physics from the other colliding object on each relevant frame so that it’s filter at any given moment correctly corresponds to the shape you want it to collide with.
Be careful about adding/removing physics bodies from objects that are presently undergoing a collision even, as it’s possible this could crash the app but I don’t know for sure.
Any way you decide to do this is going to be a bit tricky. Unfortunately box2d just wasn’t designed with this feature in mind. [import]uid: 135827 topic_id: 33248 reply_id: 132134[/import]
How are you doing the animations? Post the code and I’ll see if anything comes to mind. [import]uid: 181948 topic_id: 33248 reply_id: 132117[/import]
The way to do this is to remove physics from the object and then re-add them with a different shape. You will need to manually define the shape at each point (Or use a 3rd party tool to give you the right shape definitions). [import]uid: 135827 topic_id: 33248 reply_id: 132119[/import]
Thanks for the input, guys.
treb.stewart,
I am actually using SpriteHelper for the animation.
George18,
This seems pretty tedious especially if the animation changes often during the game and also if every frame has a different physics shape. [import]uid: 70056 topic_id: 33248 reply_id: 132133[/import]
@Falcon777 another way to do it would be to define all possible sets of physics boundaries on the object as separate shapes, then put each shape one into a different physics filter. In that case you will still probably need to add/remove physics from the other colliding object on each relevant frame so that it’s filter at any given moment correctly corresponds to the shape you want it to collide with.
Be careful about adding/removing physics bodies from objects that are presently undergoing a collision even, as it’s possible this could crash the app but I don’t know for sure.
Any way you decide to do this is going to be a bit tricky. Unfortunately box2d just wasn’t designed with this feature in mind. [import]uid: 135827 topic_id: 33248 reply_id: 132134[/import]