There's been a few posts about similar questions, but none completely address my question:
How to combine spine animations with box2d while allowing the physical model to affect the animation AND allowing the animation to affect the physical model.
Most of the ideas I've seen describe the solution in which the animation affects the physical model, but not the other way around. This sample code is such an example: spine box2d: https://github.com/EsotericSoftware/spi ... Box2D.java
Video example: https://www.youtube.com/watch?v=YvEjbQO ... t=1h12m13s
This works great, but if the boy ran into a wall, there would be no automatic way to relay that back to the animation to prevent it from going through that wall.
So to deal with this, I'm considering one of the following solutions:
- (My current favorite solution) Create a body for each attachment mesh and connect each body with a revolute joint. Designate one of the bodies (e.g. the torso) as the body that controls the world position of the animation - this body will not be updated to match the animation. The rest of the bodies are updated (by adjusting their joints) to match the spine animation. In the case of ragdoll, all spine-to-physics updates are turned off and instead physics-to-spine updates are used. Cons: seems complicated.
- Create fixtures for each attachment. Problem with this is that box2d apparently doesn't like it when you move fixtures around and at the very least it's inefficient to recreate them on every frame.
- Create fixtures for all possible positions of the animation and then activate/deactivate them on each frame accordingly. Seems like it would be too inaccurate.
- Write my own physics using spine meshes as the object bounds. - I don't have the time =(
Would love some feedback, suggestions, ideas,
P.S. Here are some other forum posts for reference:
spine box2d: https://github.com/EsotericSoftware/spi ... Box2D.java
attachment loader, rotation angles, sample code:
alignment issues: viewtopic.php?f=11&t=2040&p=10218&hilit=box2d#p10218
more example of separate skeletons:
http://www.gamedev.net/topic/624738-con ... -matrices/