Skip to content

Add constraint between two static bodies which are later changed to dynamic does not work #238

@viblo

Description

@viblo

A user of Pymunk reported that when he added a constraint between two static bodies, did a couple of simulation steps and finally changed the bodies to dynamic the bodies got NaN position. I did a little bit research and it seems like its because the constraints will try to move the static bodies with infinite force, which is then cached and not cleared when the bodies become dynamic. Issue is tracked here on Pymunk issue tracker as well: viblo/pymunk#237

This code illustrates the issue (sorry for python, but I think the main issue is clear)

>>> import pymunk
>>> s = pymunk.Space()
>>> b1 = pymunk.Body(body_type=pymunk.Body.STATIC)
>>> b2 = pymunk.Body(body_type=pymunk.Body.STATIC)
>>> c = pymunk.PinJoint(b1, b2, (0, 0), (0, 0))
>>> s.add(b1,b2,c)
>>> s.step(1)
>>> b1.position
Vec2d(0.0, 0.0)
>>> c.impulse
inf
>>> b1.body_type = pymunk.Body.DYNAMIC
>>> b1.mass = 1
>>> b1.moment = 10
>>> s.step(1)
>>> b1.position
Vec2d(nan, nan)

One way to fix it would be to reset any constraints that have a body that changes type. Looks fairly easy to do, I might do it myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions