[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Maybe there could be an expression that checks if a point is inside an object? Seems like a lot of cases the collision points are within the object, and I need a way to move them out, so I think testing if they're inside and then moving via their normal until they're out might work, but there's no expression to test if a point is in an object at the moment.

  • R0J0hound, This is great...Thank you...Though there are some oddities that I notice at times in the movement of the balls to the ideal newtons cradle, I think this is the closest...

  • Prominent

    The contact depth should be the distance from the edge, but I'll look into it. The point query condition will give a negative queryDist when the point is inside a shape.

    mattb

    That appears to be how the chipmunk library works. Those contacts flicker on and off when you look at it continually. I'll probably investigate further.

    I'll try to get those bugs fixed tomorrow. I'm also going to do some internal tweaks to better address future issues and hopefully prevent them.

    Documentation tidbit:

    The collision layers property is a list of 32 layers and whether an object is in one or not. I opted for 8 hexadecimal digits instead of 32 binary to shorten it.

    The default value: ffffffff means the object is in all the layers. Whereas 00000001 means the object is in that one layer.

    If you don't need all 32 layers and don't want to deal with hexadecimal numbers you can use 1 or 0 and have 8 layers.

    The objects can collide if any two digits are both 1. For example:

    Obj1 00000001

    Obj2 11111111

    They can collide.

    Obj1 00000001

    Obj2 11111110

    They won't collide.

    Obj1 11110000

    Obj2 00001111

    Obj3 11111111

    Obj1 won't collide with obj2 but both can collide with obj3

    Another way you can think of it is as a set of rules of what is allowed to collide with what.

    Player collides with wall, enemy and enemy bullets but not player bullets

    Wall collides with everything

    Player bullet collides with enemy and walls

    Enemy bullet collides with player and wall

    Enemy collides with wall, enemy and player bullet.

    Then you assign a layer to each

    Wall, player, enemy, player bullet, enemy bullet

    And with the rules set the layers accordingly:

    Wall 11111

    Player 11101

    Enemy 11110

    Player bullet 10110

    Enemy bullet 11001

    Another idea would be to have a seperate background layer with something moving and you don't want the player colliding with it. So for that the player's collision layer could something like 0001 and the background 0010.

  • Just couple of questions, if you could tell me from the chipmunk_nc.capx file

    1. Destroy all connected joints doest affect Pin joint created at the start of the layout?

    2. Also could you tell me what exactly is the event checking for joint impulse --> chipmunk destroy joint suppose to accomplish? When I disabled that I didnt notice any visible change whatsoever...

  • 1

    The cursor object only has the spring joint so only that gets destroyed. The pin joints are connected to the sprite object which isn't connected to the cursor object.

    2

    That event is to demonstrate joint breaking. With the event enabled pull one of the balls down. When you pull far enough the impulse on the joint will get too large and the joint will be destroyed so the ball will break free

  • I get it now...Thank you very much.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound this is brilliant, exactly what i'm after, thank you!

    Prominent you might already have tried these, but for checking internal points there's the Pick overlapping point condition, & for moving them back out the Custom Movement behavior has lots of 'push out solid' options.

  • R0J0hound, sorry to ask one more question on chipmunk_nc.capx...I noticed that when I drag a single ball to the left by a very small angle ( lets say under 10 degrees or so), sometimes the ball stops with nothing happening...sometimes all the balls start moving in a random fashion...Do you think all these are the limitations?

  • hi R0J0hound, choosing 'Is disabled' condition gives us 'For each collision pair' instead. This seems to be the only bug of it's kind

    and a thank you for this behaviour

  • Prominent you might already have tried these, but for checking internal points there's the Pick overlapping point condition, & for moving them back out the Custom Movement behavior has lots of 'push out solid' options.

    mattb , pick overlapping point doesn't work for tilemaps. But I can check what the tile is at a position, and if it is -1 it means it is outside of it. push out solid seems to push them out at closest direction, which may not be accurate. I'm using the normal to push it out so it seems to work.. Sometimes I get it still pushing it out at wrong directions, so maybe I can use push out solid if the normal sends it too far in weird cases...

    R0J0hound , do contact points remain after the on post collision event? Since it only fires once, there's no way to reference the contact point afterwards unless you store it in an instance variable- that's what it seems like anyways.

  • mattb , I just realized you can use query closest to point to find if a point is inside an object..

    it's a condition though.. so can't use it like an expression. :\

  • Updated to 2.1

    Download in first post.

    *Fix: Setting object to immovable after creating a joint in a "pre step" or "post collide" condition. Actually the fix should correct any errors claiming stuff is being added twice.

    *Fix: Setting immovable to No when it was immovable caused and error.

    *Fix: Angle would become nan if both connected bodies of a joint were immovable.

    *Fix: choosing 'Is disabled' condition would give 'For each collision pair' instead.

    *Fix: Error about removing/adding shape that isn't or already is in space.

    keepee

    Thanks, it was a typo on my part. I'm surprised that C2 didn't complain about that one.

    Prominent mattb

    Using the custom movement behavior isn't ideal for that sort of thing. Attached is a way to find the point on the edge of a shape. toggle between events 3 and 4.

    Event 3 uses the contact depth and normal to find the point on the edge, which works for other object's corners, but not the current object's corners. Not much can be done there as it's how the library works.

    Event 4 uses the query from point condition to find the closest point on the edge. This probably won't work the way you want with tilemaps though.

    Contact points are only accessible from under the "post collide" and "for each collision pair" conditions. So yeah you'd need to save the info to variables to use outside of that.

    A segment query from the object's center to the contact point may be one solution.

  • R0J0hound , I get immediate error in my game now when collision happens.

    Error: Assertion failed: Body.activateStatic() called on a non-static body.

    at assert (http://localhost:50000/rojoChipmunkBeta ... or.js:51:9)

    at Body.activateStatic (http://localhost:50000/rojoChipmunkBeta ... .js:4277:2)

    at behinstProto.updateCOM (http://localhost:50000/rojoChipmunkBeta ... js:6967:10)

    at behinstProto.updateShape (http://localhost:50000/rojoChipmunkBeta ... .js:6714:8)

    at behinstProto.changeShapeCheck (http://localhost:50000/rojoChipmunkBeta ... js:7064:10)

    at behinstProto.postCreate (http://localhost:50000/rojoChipmunkBeta ... .js:6882:8)

    at Runtime.createInstanceFromInit (http://localhost:50000/preview.js:3247:28)

    at Runtime.createInstance (http://localhost:50000/preview.js:2885:15)

    at SysActs.CreateObject (http://localhost:50000/system.js:1337:33)

    at Action.run_system (http://localhost:50000/eveng.js:1743:20)

    edit: seems to happen if create object on post collision.

  • Hmm, that's no good. I'm out of time today, so it'll have to wait till tomorrow. In the meantime you can try and comment out line 6714.

  • I commented out line 4277 and put in if(this.isStatic())return;

    Not sure how that will affect other things, but it's allowing me to continue developing stuff for now.

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