Comments (5)
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.
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.
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.
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.
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)
- Licensing confusion HOT 1
- cpSpaceSegmentQueryFirst returns wrong normal If a segment query starts within a shape
- Leaking memory on sleeping bodies
- Can new version tag be released including the sys/sysctl.h related fix? HOT 1
- Reproducable state & serialization of space
- Stackoverflow in SubtreeInsert when adding too many shapes to a space.
- simulating rolling friction with Chipmunk2D for a top-down game HOT 8
- Demo crashing in release mode [using GCC 13] HOT 7
- Segment query first, sometimes failing HOT 9
- The demo crashes whether it's built with gcc or visual studio HOT 3
- Perf improvements HOT 5
- Freezes when static body collides HOT 5
- Assessment of the difficulty in porting CPU architecture for chipmunk2D HOT 2
- Crash in debug mode using MSVC 2022 HOT 1
- Collisions and sleep HOT 1
- Is there a reason why maxForce doesnt apply to DampedSpring and DampedRotarySpring?
- Is there formatting config/rules used on Chipmunk2D? HOT 2
- Total impulse of cpDampedRotarySpring is wrong, it adds the damping instead of subtracting it.
- [Documentation] Custom cpcalloc actually does need to zero memory
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chipmunk2d.