Fixed position dynamic body

Hello,

I am trying to create a dynamic physics body that does not move when objects collide with it. I have tried adding density to the object, locking the rotation, and adding friction. However, the object still moves when the user initiates a powerful enough collision. The reason I need the body type to be dynamic is that both kinematic and dynamic bodies collide with this object and I don’t believe static bodies recognize kinematic collisions.Any help on this would be greatly appreciated.

Thanks. [import]uid: 47722 topic_id: 28402 reply_id: 328402[/import]

Hi macman,

Am I right in understanding that the object you’re trying to create not only will stay still in response to a collision, but also will be staying still in general?

One idea is to create your object as dynamic, and then create another invisiblr static body in the same position as an anchor. You would then use a weld joint to join your dynamic body to the static anchor. That way, the body is dynamic (so it will collide with everything), but because it welded to a static body, which won’t move, it itself shouldn’t move either.

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 28402 reply_id: 114653[/import]

That is a very good suggestion.

I take it further and use a far off screen static object as an anchor for all fixed position objects - anything which would normally be a static object.

This is because no object in the physics world should be static. Box2D defines collisions between static and dynamic forces as the practical application of the old adage “What happens when an irresistible force meets an immoveable object.” Therefore, any object which is not a sensor should either be kinematic or dynamic. If it really, really needs to stay absolutely fixed in place, anchor it to a static object which is out of the way - either far off screen or simply in a separate collision group from everything else. [import]uid: 8271 topic_id: 28402 reply_id: 114744[/import]

Based on Andrew’s suggestion, I’ve been working with weld joints over the last few days. However, I’ve run into one problem. I have a switch that is supposed to remove the dynamic object and switch to a new object. After adding the static object, I modified the removal code to include the removal of the static object and the removal of the weld joint (using removeSelf). However, when I set the draw mode of the physics engine to hybrid, the static physics body is still present, despite the image associated with it being removed. Does anyone have any ideas on why this could be happening or how to fix it? I’ve tried about six different possible solutions and none of them have worked.

Thanks in advance for helping me out [import]uid: 47722 topic_id: 28402 reply_id: 114889[/import]

Could you post some sample code? I think this is an ideal situation where a simplified version of your code would really help reduce the problem. [import]uid: 8271 topic_id: 28402 reply_id: 114896[/import]

Agreed, sample code would be helpful. I haven’t experienced any case in which removing the display object still left the associated physics object behind.

  • Andrew [import]uid: 109711 topic_id: 28402 reply_id: 115238[/import]