[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • I know, you probably don't have much time to fix stuff with this plugin R0J0hound , but thought I would mention that if I have chipmunk objects on two separate layers, and one layer has a different angle set, objects only use the angle of the layer they are currently on.

    So when colliding, the layer angle isn't taken into account if the object they're colliding with is on a different layer.

    Hope that makes sense.

    I test this with tilemap on a rotated layer, and an object on another non-rotated layer. Object acts as if tilemap isn't rotated. If the object is put on same layer as tilemap, then it acts as if it is rotated.

    Maybe it is a C2 issue?

    edit:

  • I'm curious to know what are some of the best ways/tips to try optimize a project using this behavior? I'm working on a game for a limited hardware and although the performance is better than with C2 standard physics I could still use some helpful advice to improve the framerate further. Obviously I'm trying to keep the object count low and in check, I've also experimented with idle/sleep time threshold values but other than that what steps could I take to optimize further?

    Also, I'm trying to add some bouncing objects into the project but was wondering what's the correct way to do this? Let's say I have a basketball that's supposed to bounce off ground surfaces. I can achieve this by increasing the elasticity value on both the basketball and ground surfaces, but if I want to have the ball also bounce off other objects and increase their elasticity too, these objects will also bounce off the ground surfaces similar to the ball. If I keep the ground surface elasticity low (say 0.2) and instead just increase the ball elasticity to something like 5, they will bounce off the ground as intended, but on collision with other basketballs they are sent flying like a missile:) Any help on what's the recommended way to set this kind of scenario up would be appreciated!

  • AnD4D

    If it crashes it's a bug, and I think that one is known. I haven't worked on it in a while but the plan was to rework the entire plugin so that's easier to fix. The crash is do to some logic error on my part, but it usually occurs when setting the mass under one of the plugin's trigger or loop events. The reason is under those events the chipmunk library itself won't let you change the mass, collision shape,... etc of an object. To alleviate that the change is just delayed till it's allowed to. In short it introduced too many special cases which made it increasingly hard to debug and fix, so an internal rewrite is needed in order to simplify things. I unfortunately don't have the time or interest to work on plugins to that extent, but at least for the most part this plugin is in a working state.

    Prominent

    Yeah, I never investigated handing layers with different parallax, rotations and such. I just left it as unimplemented. Tilemaps can't rotate as I recall, otherwise I would have let them if I could. That bug seems odd, looks like the tilemap's bounding box is being used.

    Waltuo

    Usually you'd keep the elasticity in the range of 0 to 1. I'd make the ground and the first ball 1, and the second ball 0.2 or something. When two objects collide their elasticities are multiplied together.

  • Is there a way to limit On Post collide triggers to run once? Sometimes they run more than once due to multiple collisions at the same time(as far as I can tell). I only need to do certain things based on the last collision, so when it run more than once, it makes errors.

    edit: okay.. seems I figured out the issue:

    I had a condition Sprite.Chipmunk.jointType("Tag")="" in the on post collide. And I was adding the joint in the event, however, it seems it doesn't add it immediately or something.

    I changed it to rely on an instance variable instead, and that fixed the issue.

  • A quick way would be to use a variable like this:

    global variable once=0
    
    on collision
    once=0
    --- set once to 1
    --- do stuff
    
    every tick
    --- set once to 0[/code:239878ee]
    
    That way you'd only get one event per tick on that object type.  Actually you'd want an instance variable instead to have one collision per instance per tick.  Or if you wanted only one trigger per pair of instances you could use a dictionary to keep track of it like:
    
    [code:239878ee]on collision
    X dictionary: key exists min(sprite.uid, sprite.chipmunk.otherUID)&":"&max(sprite.uid, sprite.chipmunk.otherUID)
    --- dictionary: add key min(sprite.uid, sprite.chipmunk.otherUID)&":"&max(sprite.uid, sprite.chipmunk.otherUID)
    --- do stuff
    
    every tick
    --- dictionary: clear[/code:239878ee]
    
    I do not know if the chipmunk library has anything to help with that.
  • Thanks, that dictionary method looks useful- i'll have to remember that if I need to check pairs.

  • Any way to change friction/elasticity per collision? I'm trying to get a collision response to make an object bounce without friction, and then set it back so that other objects keep their friction/elasticity when they collide.

    I also tried calculating my own response by reflecting across normal, etc, but it doesn't work.

    edit: I got the reflecting working, but the friction still gets applied. I can't find a way to turn off the friction during a collision.

  • alright, this seems to work:

  • edit: figured it out- tilemap was set to box instead of poly.. not the polygons are working per tile.

  • Apparently you can't collide two segment shapes together??

    is this a bug R0J0hound ?

    edit: I checked the chipmunk docs, and apparently segment shapes can't collide with other segment shapes.. I guess I'll have to try and find some alternative.. maybe a thin polygon- I'll try that.

    edit: I tried a thin polygon, but I get an error stating that the moment of inertia must be positive and non-zero. line 52 (col 3).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Newer versions of the chipmunk library can have segments collide with segments, but it wasn't ported to JavaScript when I made the plugin.

    I'm guessing you got that error because the inertia was set to zero. Maybe because of zero area. Just make it a hair thicker.

  • R0J0's been quite lately because being hound he was looking for me Lord Shiva

  • R0J0hound , I found a bug that causes the game to freeze <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    capx: https://1drv.ms/u/s!AhHSZHEulqh_gWHiXC4TP0AV8S7_

    Seems to happen when you use a 'on pre collide' for an object, and set its velocity at the moment when a group of object collide at the same time.

    If you run the capx, it will freeze after a moment when a few boxes collide at exact same time, I think.

  • R0J0hound , actually.. it appears it happens when an object is asleep. I positioned one to sit above the tilemap and forced it to sleep state on start of layout, and then on pre collide it immediate freezes when velocity is set.

    edit: I'm guessing the pre collide isn't meant for applying velocity/etc.

  • Prominent

    That's odd, but I don't think i'll be able to fix it. It appears to be a bug with the library itself.

    When those triggers are called the simulation is in a locked state where only certain things are allowed to happen. To make it work the library delays certain things from being done until the simulation is no longer in a locked state. Also on top of that i've added stuff on top of that. The result is too many cases where things can fail.

    The bug here is with waking up sleeping objects when the library is in a locked state.

    I guess the workaround for this particular case is to either disable sleeping, or keep those objects awake with a "every tick: wake sprite" event.

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