[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Another useful application of disabling/enabling joints would be if you want to switch between joint types to control the movements of objects that are grouped together in specific ways. I think this could open some unique game mechanics that might be otherwise difficult to manage. This might be obvious to you, but just thought I'd mention it anyways since I think it would be really useful.

  • R0J0hound there's a minor bug when you try to alter the mass of an object with a polygon collision shape. Not a biggie, the workaround is to set coll shape to box before setting mass, then switching it back to polygon afterwards.

    Here's the error message:

  • help helP!!! i cant figure out how to stick to seperate sprites to each other when they both have physics enabled?? like a helmet on a head stuck, both sharing same rotation an angle? Simple but theres no way and not sure what joint to use.... should i make objects like that immovable and simply set the angle? but what if i need to to interact with normal collisions also? whats the physics way to do it???

  • jeebroniz here's what rojo said about the joint part of your question:

    [quote:2o3yi1ny]According to the chipmunk forums the way to join two objects together is with two joints. A pivot and a gear joint. I apologize fo the seeminly complicated formula used for the phase of the gear joint. It's the signed angle difference between the two object angles. angle(0,0,cos(a-b),sin(a-b))

    This is the capx he posted:

    The easy way to disable collisions between the two objects while still keeping their physics collisions with other objects active is to set their collision group property to the same non-zero value.

  • jeebroniz here's what rojo said about the joint part of your question:

    [quote:b72y9s4y]According to the chipmunk forums the way to join two objects together is with two joints. A pivot and a gear joint. I apologize fo the seeminly complicated formula used for the phase of the gear joint. It's the signed angle difference between the two object angles. angle(0,0,cos(a-b),sin(a-b))

    This is the capx he posted:

    The easy way to disable collisions between the two objects while still keeping their physics collisions with other objects active is to set their collision group property to the same non-zero value.

    wow man thanks a ton! , i totally forgot about the obviouys X and Y joint I had used previously to get more rigid hinges..

    now i wonder how most people approach AI using a physics enabled environment?

  • Prominent

    I hadn't anticipated that case where a joint still affects a disabled object. I guess I may need to remove the object further from the sim, as right now it just is removed from the simulation space. To be able to disable joints would also need some some work, since it's not nearly as straightforward as disabling objects is now. This will have to wait until I get to re-reviewing the code.

    mattb

    Thanks for the bug report as always. I haven't touched the code for a bit so I need to re-familiarize myself with it. Well, that and I need to then rework a lot of it to address the requests and feature requests of the last few pages. I'll see if I can make some time this week perhaps.

  • R0J0hound

    Prominent

    anyone argh

    Any idea how to handle damping with a force-based magnet/point attractor so that attracted objects don't overshoot & fly around the centre? I've tried a bunch of expressions where force decreases towards the centre, with an opposing damping force based on velocity, & nothing works.

    The current method I'm using sets velocity directly, & it's fine until stuff gets dragged through walls. I'm hoping that forces will solve this, since they're always the recommended way of moving things in physics engines.

    https://dl.dropboxusercontent.com/u/523 ... oblem.webm

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To dampen the velocity of an object that has forces applied, I think you could just multiply the velocity by something like 0.95 (or a value near 1) every 0.01 seconds or something like that..

    To help prevent objects sticking into other objects, you could try moving it out at the angle of the collision's normal a distance of the collision's depth(or maybe it's the negative of the depth?).. You'd get these values on post collision and perform the move then.

    That is what I would try.

    edit: btw, thanks for the info r0j0hound , I kind of thought it might require a lot of editing, but figured I'd mention it anyways in-case you ever see an opportunity to try it.

  • Prominent

    Yeah i've been doing that kind of velocity damping. I want to see if a force only approach is possible, to see if that improves collisions.

    Here's a comparison of velocity vs force based magnets (very simple with no falloff or damping, just constant velocity & force applied) to show how much better collls are when you don't mess with velocity:

    https://dl.dropboxusercontent.com/u/523 ... rison.capx

    EDIT: I think i've cracked it - damping force just needs to be a force opposing the object's angle of motion (chipmunk has an expression for that), proportional to its speed. Throw in a multiplier, negate gravity & it seems to be good, perfect collisions.

    new capx - https://dl.dropboxusercontent.com/u/523 ... mping.capx

  • how do you force a rotation to a point with this behavior?? ive got overlapping parts all joined together using the physics joints someone posted in this thread but when rotating using built in behavior some of my parts start spazzing out since i guess they need to rotate naturally through physics?

    any help would be appreciated

  • It probably depends on what you're trying to accomplish. You could try maybe setting the velocity after you rotate it to the velocity it was before the rotation. Maybe setting angular velocity to 0.

    Do you want the rotations to have momentum, so after they are rotated they continue moving?

  • Hi. How can I set Chipmunk2D 7.0.1 to construct 2?

  • Hi. How can I set Chipmunk2D 7.0.1 to construct 2?

    I assume this is the latest incarnation? If so, you would need to do what R0J0hound has done and use the SDK to integrate it into C2, which is not a small task.

    The other option would be for R0J0hound to update his code, but that would be entirely up to him.

  • jeebroniz

    Here's how I would handle rotating to a target angle using torque:

    https://dl.dropboxusercontent.com/u/523 ... mping.capx

    It uses the same principle as the magnet thing I posted here the other day: apply torque proportional to angle difference of object to target, then add an opposing torque proportional to the object's angular velocity to act as damping.

    It'd crude & fairly math-free, but completely force based so won't cause the issues you get when directly setting velocity or position.

    Rojo gave a better example here which uses proper torque calcs involving inertia:

    viewtopic.php?f=147&t=122190&p=871121&hilit=physics+rotate+towards+angle#p871121

    navel35

    Rojo's behavior is built on a javascript port of Chipmunk2d 6.1.1 & I think that's unlikely to get updated.

  • navel35

    Only version 6.1.1 will probably be used for the lifetime of this plugin. To use version 7, I would have to port it to Javascript myself, but I don't have the time for that. The only additional feature it would have is rounded shapes, but it's not essential.

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