[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • The physics is updated every frame. 1/30 just means the amount of time simulated in a frame.

    It looks like it's just a difference between the libraries. It may be corrected in a newer version of the chipmunk library since it changed it's collision detection code. Unfortunately there isn't an updated js port.

  • mattb , you might be able to move it out based on its' collision depth to negate the overlapping.

  • R0J0hound , is there an explanation of the jointimpulse expression? Is this the tension between joints attached to two objects? I'm trying to figure out how to get the tension or force of an object pulling on another. Maybe jointimpulse will do it?

    edit: i found this in the chipmunk docs "The most recent impulse that constraint applied. To convert this to a force, divide by the timestep passed to cpSpaceStep(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold."

    Would I divide the jointimpulse by 1/30 ? That would give me a larger value, which wouldn't make sense. Or maybe it means to multiply it?

  • That should be right. By definition impulse=force*time. So to get the force dividing by the time (1/30).

  • R0J0hound thanks.. When I apply an impulse or force on an object, how would I apply it at a layout x,y coordinate? The only options are polar and rect, which I assume are relative to the object (rect is relative to a non-rotated state?). If I have a joint attached to an object and want to apply a force on the object at the location of the joint, there doesn't appear to be an intuitive way to do this.

  • Right, forces and impulses are relative to the object, object rotation is ignored. If you want a force/impulse to a particular layout position use polar with the angle(self.x,self.y, posX, posY) expression.

  • R0J0hound , Oh okay, I see now. For some reason I didn't realize I could do that. Thanks!

    I've been getting more comfortable with the behavior. Haven't really ran into any major issues. But I have noticed that if I leave a game running for a while, it slows down a lot, and if I restart the layout everything becomes quick again. Not sure why it would do that. I know someone else mentioned it in this thread previously.

    Btw, Is the pre-step condition only useful for negating gravity?

  • R0J0hound , also, can you tell me why commenting out this pin joint has the shown effect?

    I don't understand why the pin joint is needed.

  • R0J0hound thanks for this wonderful plugin.

  • is the angular velocity implemented in this version?

    quoting the chipmunks website documentation:

    "The surface velocity of the object. Useful for creating conveyor belts or players that move around."

    seems like that could be very useful

  • has anyone implement a platformer movement with this?

    is it possible to set the player's velocity manually without it going through walls or pushing heavier objects?

    a kinematic body perhaps would be best for this job i dont know if that possible in this plugin

    or maybe pinning the player to a dummy with a pin joint

  • bla6546 , this is a simple example of something I put together. I didn't really spend too much time on a platform movement yet, but you can see the basics already.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Anybody tried this behavior in Crosswalk? Using Box2D I loose 30 FPS

  • , I tried this a couple of weeks ago on my laptop and its performance was almost identical to box2d web (and asm.js - Ashley and I disagree on the latter's performance hike).

  • Prominent

    The slowdown is from a memory leak somewhere that's preventing stuff from being garbage collected, but I haven't had much luck identifying where, although hearing that restarting the layout speeds it up is helpful to know.

    Negating gravity was the main purpose for pre-step. There may be other uses, since the chipmunk library has it too.

    Joints in the chipmunk library are velocity based, which means they change the connected bodies' velocity so that the joints match up. The pin joint in your capx from best I can tell does a better job than just setting the object's position. Without the pin joint you're just transporting a free-falling object, so the y velocity would always be increasing and make it swing more. Maybe you could pin to an immovable object and move that if you want the pin point to move.

    With physics libraries it's generally better to constrain objects with joints than setting position and velocities. At least from what I've seen.

    bla6546

    It already has angular velocity.

    "surface velocity" may indeed be useful, I'll put it on the todo.

    A kinematic body is just a body not affected by gravity, correct?

    For that you just undo the gravity in a "pre-step" condition like so as I recall:

    Pre-step:

    Apply force rect(0, -Self.Chipmunk.mass * Self.Chipmunk.gravityY)

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