Git Product home page Git Product logo

Comments (5)

viblo avatar viblo commented on September 27, 2024

Some more research and I see that the bodies have their velocities updated by the constraint as well.. So it should be reset. On the other hand, it is valid to give a kinematic body a velocity, so maybe its not good to reset it. I could see a case when a kinematic body becomes dynamic, and in those cases it feels like the proper thing to do is to keep any velocity values..

Now I wonder if the correct fix would be to only apply the constraint impulse to dynamic bodies. That would fix all issues I think. The downside I see with this is that its an additional check in the 'hot path' of the constraints...

from chipmunk2d.

slembcke avatar slembcke commented on September 27, 2024

Hrm. So it was certainly never intended that static and/or kinematic bodies would be constrained together. They already represent edge cases of objects that cannot be moved, so adding constraints that try to move them doesn't make a lot of sense. As you say, detecting such a condition adds a (probably not statistically significant?) conditional to the hot-path. If this was a more common issue I might be more amenable to making the change, but this is the first time I've heard of someone wanting that use case in 15+ years.

from chipmunk2d.

viblo avatar viblo commented on September 27, 2024

I think he did it because just because it was natural and he didnt know it would break. His code had two "balls" attached together with a Pinjoint drawn on screen with debug draw. Then when user clicked, the balls became dynamic.

For this kind of quick physics simulations I think it can make sense to be able to "arrange" the scene first, then activate (make dynamic) part of it. If nothing else its quite helpful to be able to see what it looks like before its actually simulated as dynamic. If its not supported you would have to duplicate the constraint drawing code separately (or maybe some other workaround)

I should add that this was a beginner both in coding and using Pymunk, took some time before I figured out his problem.. While I think the use case is reasonable, I can agree that its also reasonable to not allow this.. its easy to explain that constraints will make a mess when they interact with bodies with infinite mass etc.

from chipmunk2d.

slembcke avatar slembcke commented on September 27, 2024

Hrm. I'll think about this a bit. It is 2023 after all... Computers are plenty fast to handle a few runtime sanity checks, especially when the code has other, larger performance gaps anyway...

from chipmunk2d.

viblo avatar viblo commented on September 27, 2024

Im not sure if you checked the code I added. If not: What I did was reset the body v and w, and jAcc on the constraints if body changes from non-dynamic to dynamic, and its attached to another non-dynamic body with constraint. I do not think this has any noticable effect on performance since its only run when body type is changed. Of course it still wastes some resources while everything is static, but I think those that have code where this waste is relevant also are not using debug draw and should be able to optimize this by not adding the constraint between non-dynamic bodies in the first place.

The other option in my mind would be to just forbid this case with an assert. That would at least make it clear that its not supported with static-static constraints. I think this is also a reasonable solution. This could be checked when the constraint is created (and to make it tight also when body type is changed)

So far I havent actually included this whole fix in a released version, so the assert option is totally valid. (I want to do something to help the user, but if thats this fix or a assert that prevents it Im not sure. Only that NaN values are difficult to troubleshoot, especially since they often show up by breaking drawing but not actually at the place that created them in the first place. )

from chipmunk2d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.