-
Notifications
You must be signed in to change notification settings - Fork 361
Open
Description
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
Labels
No labels