[BEHAVIOR] Chipmunk Physics

3 favourites
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Here's some basic benchmark scenes to compare box2d with chipmunk. Both give me very similar fps & cpu readings but I didn't leave them running for long. A noticable difference between the two is that chipmunk ignores the size of the sprites when applying forces; with c2's default physics you can see that larger sprites lag behind as you move the mouse around.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A noticable difference between the two is that chipmunk ignores the size of the sprites when applying forces; with c2's default physics you can see that larger sprites lag behind as you move the mouse around.

    Good to know- I hate how the box2d implementation messed with the mass based upon sprite size. If you set an objects mass, it should stay that value regardless of the scale of the sprite.

    +1 for chipmunk!

    boybacteria , cool icon!

  • Updated to version 1.3

    * Fix: removed an alert left in the set mass action.

    * Fix: speed expression was broken.

    mattb

    I'll have to give this more thought to keep things simple. Ideally we could coose from:

    layout x,y

    imagepoint

    relative to orientation of the object *(what's currently done)

    boybacteria

    Thanks for the icon. It makes it look like a physics behavior as much as the name does.

    edit: opps, forgot to add it. will next update for sure.

    spongehammer

    That's a typo on my part. I used ^ which in js means xor instead of squared.

    Prominent

    The built in physics' mass property is more like density, since the box2d mass is calculated with the area of the shape.

    You can do the same in this behavior by setting the mass to with the area expression.

    mattb

    Here's a capx that sets the mass based on object size.

  • I'm a bit confused on how the torque works... check out this example:

    [attachment=0:1gf6rdrq][/attachment:1gf6rdrq]

    The one on the left is with the default physics behavior... I obviously haven't done much in this example for Chipmunk... but I'm just curious if there is anything I can do to mimic this? Note, the black dot is there for you to drag over to the spinning 'propeller' to stop it from moving.

    There is no 'apply torque'.... only 'set torque'.

    Ideas? Thanks!

  • Nitro187

    "Set torque" does what it says, it set's the torque. The only difference to apply torque is possibly adding to the torque, but you can do this with "Sprite.chipmunk.torque + something".

    Here's it working with chipmunk

  • Hey man!

    However, there doesn't seem to be any Angular damping in your plugin... The one on the left is Chipmunk, the one on the right is the default physics behavior. For some reason, the chipmunk one constantly speeds up faster, and faster, rather than staying at a constant speed. (Give it some time, you'll see it's very apparent)

    The two black lines are there for collision purposes... (I don't want them colliding with the propeller). The default physics plugin has the ability to disable, or enable specific objects, rather than settings layers, which can cause a problem... but so far it hasn't...

    Lastly, I'm guessing the Concave polygon support is what you mean for the behavior it has with colliding with the ball? I notice chipmunk does not support collision polygon's... so perhaps that's why it's not interact the same as I was expecting.

  • R0J0hound

    Thanks for the mass/size example.

    I'll have to give this more thought to keep things simple. Ideally we could coose from:

    layout x,y

    imagepoint

    relative to orientation of the object *(what's currently done)

    My preference would be imagepoint, in keeping with C2's physics behavior. I do prefer your method of object picking by UID though, & it'd be nice if you could put -1 into the UID box as a 'constrain to world' feature.

    Nitro187

    For angular damping make a damping variable from 0-1, then you'd add the action: Set Chipmunk angular velocity to Self.Chipmunk.angVel * 1-damping

  • Nitro187

    You're right there is no angular damping at all so the object would accelerate indefinitely. It can be useful though so I may eventually make damping built in.

    The way to disable collisions between object's is to use collision groups and layers. They aren't colliding because they both are in the same collision group.

    Actually box2d doesn't work with concave objects either, both libraries need the concave polygons to be converted to multiple convex ones. The built-in physics behavior does this automatically for you, but this behavior doesn't yet.

    mattb

    -1 has a useful meaning for uids that means no object. Instead would being able to type "world" be better? It would make it more clear what was intended.

  • Yes that'd be great thanks.

    I was wondering, since chipmunk has raycast options could I somehow get a ray hit position & normal (on eg. an immovable sprite) without shooting out physics object then using post-collision info? I see there's a raycast query condition, but that's only for picking the first object hit.

  • mattb

    The "pick overlapping line segment" should do it, but it seems to be bugged in the last version I uploaded. The fix will have to wait till I finish with the other stuff I'm adding, which is requiring lots of code changes.

    Stuff like this:

    https://dl.dropboxusercontent.com/u/542 ... index.html

  • cool, tilemaps.. Hope you provide some detail on how that is handled once you get it sorted how you want it- I'd be interested in knowing how it works. One thing that has me wondering is if the tilemap will get updated if the tiles change during runtime(if you erase or add tiles).

  • Updated to version 1.4:

    Link on first post.

    * Added the new icon. Credits to

    * Added: Polygons can now be concave. Internally they are converted to convex polygons.

    * Added: Tilemap objects now work. See note[1]

    * Fixed javascript error with "line segment query" condition.

    * Fixed bug with queryNormY expression. Was the same as queryNormX.

    * Change: The default sleepTimeThreshold is now 1 second. It was 0.5 before, and objects fell asleep to quick.

    * Joints updates:

    • Added the ability to use a postion on the layout or an imagepoint to determin where to connect to objects.
    • Added: Now you can attach joints to the layout by using -1 for the uid of the second object.

    [1] Tilemap notes:

    Tilemaps ignore the "collision shape" and "prevent rotation" will always be considered "yes".

    The area expression for tilemaps will return 0.

    Changes to the tilemap are not detected currently, so the collision won't change if the tilemap is changed. A workaroud is you can force an update by changing the size of the object.

    Prominent

    The collisions won't automatically be updated if the tilemap is changed. You can manually force an update by changing the tilemap's width.

    -cheers

  • mattb

    Here's an example of the line segment casting. The query conditions also set it's query expressions which can give normal and hitpoint.

    "pick overlapping line segment"

    Picks all object's whose shape overlap the line. In addition to picking the objects, info about where the line hit, and normal are accessible from expressions which all start with "query".

    "raycast and pick first hit"

    It's about the same as the one above, but it only picks the first object hit. It also gives the ability to filter out objects by collision layers or group. It sets the query expressions as well.

    Note

    :

    "pick overlapping line segment" isn't working all the way with concave polys or tilemaps, but the other condition is working fine.

  • Prominent

    Thanks!

    R0J0hound

    It's indeed a strange name for a physics engine

  • Rojo this is awesome, it's opened up a huge range of game design possibilities. But it does mean that I now have to rewrite my whole game (probably only with half as many events)

    I've attached a test capx for everyone to see how raycasting works with the various collision shapes chipmunk has to offer, amazing stuff.

    By the way Rojo, the raycast query doesn't seem to work if chipmunk is used as a family behavior. Not a big deal but I thought I'd mention it.

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