[BEHAVIOR] Chipmunk Physics

  • R0J0hound

    I added a motor joint to yellow, and it did stop it from getting displaced, but red still gets displaced, and yellow also gets displaced if I make the black sprite collide with yellow directly.

    From what I can see the C2 Physics just stops or slows down its rotation to prevent displacement while Chipmunk just rotates regardless, which I guess is a more consistent but with the side effect of displacement.

    I guess it is how it is. Only if the standard C2 Physics had collision filtering per instances of the same object like Chipmunk does. And looking at the files It looks impossible to hack it into the C2 physics behavior.

  • You can also set the strength of the motor. By default it will use up to an infinite force to make it turn. There’s an action to change the setting of a joint by tag. Use “” for the last created joint.

    I forget if there were other settings you could do for other joints. Guess you may need to refer to the chipmunk manual. This plugin is just a wrapper for the chipmunk library. There are things it can do that I’m not familiar with.

  • Oh ok I'll look into it then. i wasn't aware of a motor strength option. Thanks.

  • R0J0hound

    Not sure if this is a bug or not, but it seems in Chipmunk the 'angular velocity' set is twice as fast as it should be.

    I used speed=distance/time. Constant time, a set target angle, I calculate the angular speed. I used a timer to stop the rotation after the set time.

    In standard C2 physics behavior it reaches the target angle as expected, but in Chipmunk it would over rotate, then I just divided it by 2 and then it worked fine. Both C2 Physics and Chipmunk is stated as degrees per second.

    This does not need any updating of the behavior as we can simply just divide by 2, but I thought I'd put it out there.

    Also Chipmunk crashes if I make an object rotate past its min or max angles set in its limited rotary joint.

  • It’s twice as fast because the timestep is set to 1/30 by default. Setting it to 1/60 will be closer to par. You can also set the stepping from fixed to frame rate independent but it seemed to make things more unstable.

    That’s no good it crashes. Guess that goes along with not setting position and velocity for best results, which includes angles.

    Sounds like something that would need to be fixed in the library itself.

  • Thanks for clarifying. My bad.

  • R0J0hound

    Do you have a discord or any means of privately messaging you? I need your feedback on something. Might as well post it here, doesn't have to do anything with chipmunk


    Was trying to make a voxel type editor but it is not very efficient at all.

  • I have a discord I haven’t used in ages. I probably should install it again.


    My discord name is reddog

    Had a look in your capx. Didn’t have “Rex function” or “polygon” installed so I removed them. Looks like one wasn’t used and the other, polygon was just another option from paster.

    I will say the polygon plugin is probably your biggest bottleneck. It has the same issue the canvas plugin had. It draws to a hidden canvas first and is copied to a webgl texture. This is slow and uses a lot of memory when drawing many polygons.

    I noticed you’re using some JavaScript. I usually define the functions once in a start of layout. To make the functions accessible later you’d define them as

    window.myfunction = function(){};

    Instead of

    var myfunction = function(){};


    function myfunction(){}

    And the beauty of it is you’d still be able to call the function as myfunction().

    Window is the global object.

    You can do it with just events as well. Might look more readable.

    One thing I do to make my expressions more readable is to avoid using tokenat or even array.at as much. Probably just a personal preference.

    For max performance you could do almost everything in JavaScript and only do minimal stuff in events like add cubes, set the view rotation, and request it to be drawn. Kind of loses the fun of using construct though if you run into js errors.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Oh thanks for looking into it. I kinda just forked it from things I found from google searching. I have ~0 knowledge of JavaScript (if any) and to be honest C2 is the only thing I am familiar with.

    I indeed was switching between polygon and paster. I just left both in as an option. Polygon has a 'draw line' option which helped distinguish the cubes. Paster is in much lower resolution and as the performance was already slow I didn't attempt to see how it would look if I increased Paster's resolution.

    What I attempted to do was to only calculate the 3D view of one cube at the center, and then to just apply it to the rest of the cubes, maybe helping in performance. But I couldn't figure it out. As it is now it calculates the view for every cube.

    I think it would be great if everything could just be done in javascript for performance but that is way beyond my knowledge.

    I will define the function onStartOfLayout and see how it goes. Thanks

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)