Hi, I'm new to box2d, and using jbox2d in my project. I used setXForm to set a static body's position. I moved the body down, and bodies on it dropped. But when I moved the static body up, bodies on it didn't move until the static body was above them, and then they all dropped down. I did the same way with chipmunk and it works. So in jbox2d, how can I move a static body up, and let bodies on it moves up with it?
problem with moving static body
JavaFirst of all, which version of JBox2D are you using?
Let me repeat what you said so I'm sure I'm understanding the situation.
You have a static body and dynamic bodies, and the dynamic bodies are sitting on top of the static body. When you move the static body down by just setting the position, the dynamic bodies will fall and correctly bouce/interact with the static body. BUT when you try to set the position of the static body up, the dynamic bodies become 'imbeded' in the static body and don't move back out?
Let me repeat what you said so I'm sure I'm understanding the situation.
You have a static body and dynamic bodies, and the dynamic bodies are sitting on top of the static body. When you move the static body down by just setting the position, the dynamic bodies will fall and correctly bouce/interact with the static body. BUT when you try to set the position of the static body up, the dynamic bodies become 'imbeded' in the static body and don't move back out?
Yes, that's exactly the situation. I'm using JBox2d 2.0.1, and I got it from the sourceforge project.
At this point, from what I know about the behavior of the engine, I think that the only way for this to behave correctly for you with the 2.0.1 release would be to have that object as a dynamic object, and use joints to anchor it.
Box2D is having it's next point release (should be soon.....), which has the type of moving static body you're talking about, called a kinematic body. I'm working on updating the Java port now, so for now try to use joints with a dynamic body, and when we have the next release it'll be easier.
Box2D is having it's next point release (should be soon.....), which has the type of moving static body you're talking about, called a kinematic body. I'm working on updating the Java port now, so for now try to use joints with a dynamic body, and when we have the next release it'll be easier.
Thank you very much. I'm looking forward the next release. It's really a nice physics engine.
Another question, can I continuously filter a collision? It seems that I have to let the dynamic body jump up and fall down to generate a new contact with the static body, and filter the collision. Is there a better way?
I'm really not sure, you could ask around in the general forums though, they might have a solution for you
Original thread: https://box2d.org/forum/viewtopic.php?t=4259