[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • R0J0hound , Is there a way to pick a joint based on its index?

    For example, I want to loop from 0 to (Chipmunk.jointCount-1), and then pick an object by uid based on Chipmunk.jointOtherUID(loopindex). I tried this, and doesn't seem to work.

    I don't really want to have to store a list of joints an object has if I could just cycle through them based on their index.

  • Prominent

    That should work. I'll have to look at it tomorrow to see why it doesn't.

  • R0J0hound ,

    here is a capx showing the problem in a simple scenario.

    edit: here's a new capx: http://1drv.ms/1R5XwJ6

    edit: it seems to not work if it is inside a post-collide. It works outside of it though. I need a way to do it inside the post-collide- I'm assuming it is a bug?

    edit2: also, I just noticed in this case it adds the joint twice since the collision events run for both objects that collide.. If I try to add a condition to check if a joint was added(so that it won't add another), it won't find that joint so it will add the extra joint anyways. I think this is related to the joints being updated at the end of the event cycle. If there were a way to update the joint list sooner or something, it would make things easier to manage.

  • Prominent

    It only doesn't work for joints that were just added in a post collide. It has to do with chipmunk not allowing anything to be added or removed during a pre or post collide, so instead the plugin delays it slightly. The unfortunate drawback is it causes a lot of bugs related to stuff just added in those triggers.

    I don't have a simple fix for it, so it's an open issue for now.

  • R0J0hound , thanks for the explanation. I was looking through your code trying to understand how things connect.

    Have you thought about making a tutorial on how to port an existing library to a construct2 plugin/behavior? I'd be really interested, even if it is something simple- just to show how to integrate someone else's code with construct's.

  • Prominent

    I started a topic here about a way to use a third party library without writing a plugin:

    There are pros and cons of doing it that way. A pro is you can access everything a library has to offer instead of going through a wrapper that may not allow everything. A con is you're limited to what you can access from events.

    Actually making a plugin is similar, but you have to design the ACE's in a way that's usable for C2.

  • Ah cool, I never thought of doing something like that. Wasn't what I had in mind, but I'll have to try this method out sometime.

  • Are there any examples of switching between chipmunk physics and standard platform behavior (for player character) as needed? Is this feasible or is it just best to forget it and stick with either no physics at all or try to build everything with physics objects and have them enabled all the time?

  • Waltuo

    I'd recommend just using physics, but you could try it. Whenever you switch between the two be sure to set the velocities from the other behavior.

  • Waltuo , I would just use chipmunk to create the platform movement. It's not that difficult to setup if you understand how chipmunk works. If you can get it working with chipmunk, you'll be more knowledgeable on how to use it for other things, etc.

    here's a gif of something I'm working on that shows a basic platform movement using only chipmunk: http://i.imgur.com/vtWs7Ch.gif

    An important step is to disable friction on the player while moving it, and then reset the friction when move input is released (and also when player is on the ground; you need a way to check if it is or not).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound , I'm trying to create an elevator. I'm trying to make the elevator not receive any forces from other objects when they touch, so that the force I apply on the elevator is the only force influencing the movement. Any ideas on how to accomplish this?

  • Prominent

    You could try giving the elevator a mass of infinity and just set it's velocity.

    Alternatively you could use joints to emulate how an actual elevator is built. Maybe a groove joint with distance joint that you adjust the length of.

  • R0J0hound , I tried setting the mass to Infinity, but it causes errors related to collision stuff. I'm not sure why.

    I also thought about using joints, but I'm not sure if it would work the way I want it to.. I was going to see if I could add some action to discard the effects of a collision on a chosen object, but wasn't sure where to start. Is that something even possible?

  • Prominent

    Hmm, I think I had to work around that infinity mass issue elsewhere. So scratch that for now.

    Maybe we could do something in post collide. You can get the impulse of the collision with an expression, so maybe you could apply an opposite impulse to negate the force.

  • R0J0hound , post collide only triggers once I think when it first collides, but if the player is standing on the elevator, the elevator would need to continuously negate the forces pushing down on it. I tried anyways, but elevator just gets pushed down.

    I also tried the foreach collision pair, and seeing if I could negate forces, but didn't have any success with that.

    I've also tried using another object to position the elevator to as a way to keep the elevator from moving, but then it causes objects to sink into it. I assume because it is still getting pushed but the position becomes reset.

    :

    edit: also, another reason not to use joints is if the elevator must change direction while moving.

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