[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Thanks R0J0hound, however, I'd prefer not post that capx, since it's an almost finished game project. I'm trying to replicate the problem on a fresh capx, but so far no luck... perhaps some other part of my code is causing it, so I will have to look deeper into it and update here in case I discover a reliable way to replicate it.

  • You shouldn't need to use dt anywhere.

    I didn't realize this, & I see the same is also true of c2's native physics which defaults to the same fixed timestep. Time to multiply all my force vars by 1/60...

  • I'm making a game that uses chipmunk's slide constraint for swinging rope segments, adjusting the rope length by setting the joint's max distance value (which is a hacky approach i know). It all works perfectly apart from one thing: if you run the attached capx & press the up arrow key to shorten the rope, you'll see some wild collision as you clip a corner.

    Now if you set Prevent Rotation on the red sprite this doesn't happen - you just get dragged up with a bit of intersection, but no crazy swinging.

    Can anyone think of a workaround where I don't turn off rotations?

    (note: the ropes in my game never intersect with scenery because there's a wrapping system; this is just a quick example)

  • mattb

    One idea that may work is use a force on the object toward the base of the rope and just set the length as it gets closer. That may be more true to life where a force would be used to pull the rope in. You could also instead set the velocity of the object parallel to the rope as well, which would make the rope retract at a constant rate. For the latter you'll need this formula to get velocity along an angle:

    velocity at angle = vx*cos(ang) + vy*sin(ang)

    So given:

    ang= angle of rope

    and

    rope_vel

    We can set the velocity so the perpendicular velocity stays the same and the velocity along the rope is whatever value we want.

    perp_vel= vx*cos(ang+90) + vy*sin(ang+90)

    vx=rope_vel*cos(ang) + perp_vel*cos(ang+90)

    vy=rope_vel*sin(ang) + perp_vel*sin(ang+90)

    Then as with the first idea only set the rope length as the object moves closer.

    Edit:

    A third idea would be to set the maximum force of the joint so that the collision isn't as radical.

  • I think your idea of setting velocities separated into components that are along or perpendicular to the rope is the approach i should have taken from the start. Although I did try something like this & didn't like how the player's angle wasn't affected.

    Retraction/extension forces I found too hard to tweak - they always gave too much acceleration, & the damping needed to compensate interferred with the overall feel of swinging (probably my bad coding though).

    Maximum joint force seems to be just the hacky fix I was after though, thanks <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    By the way here's what I've been making: https://dl.dropboxusercontent.com/u/523 ... index.html

  • R0J0hound can i use it for altering the gravity to be towards Z axe? like in 3d? where u have x (lft right) y (up down) but towards Z(altitude?) thanks need to know how to achieve it with this plugin, and if its even possible, i need it to be able to use with Q3Dplugin axes, like a 3d gravity ability.

    Edited

    Bummer ... Thanks keep up the good work.

  • The plugin only does 2d physics so using z is not possible with the plugin.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound - any idea what's happening here? The reason I'm trying this is to see if I can redo my rope wrapping system to use segment collision shapes & contact points. The contact points work perfectly, but I can't get the rope's position post collision.

  • Nevermind, got it to work with a pre-step event...

    ***EDIT - a better way to get the colliding object's position post collision is by using ObjectName.Chipmunk.local2worldXY, which lets you set an offset from the object's CoM, so in this case it would be Rope.Chipmunk.local2worldXY(-Rope.width/2,0) to find the start of the rope.

  • Hi R0J0hound,

    Firstly I just want to thank you for this excellent behavior, it pretty much fixes all the things that I was finding frustrating with the Box2D behavior.

    One thing I cannot seem to find though, and I`m sure I must be missing something obvious, is the ability to 'weld' objects together. Essentially I want to create complex shaped objects by welding two or more objects together, there is no movement between the two objects being welded.

    A good example (using Chipmunk) would be the Motorbike`s and tank`s bodies in this video:

    Any help would be much appreciated.

    RR

  • Hi,

    I export capx and get error

    [quote:1g9fk14x]Uncaught ReferenceError: cp is not defined

    and black screen while runtime

    I am using the latest version.

    Edit: with minify

  • May I ask why "sleep" is measured by time, i.e. all physics instances will sleep at the same time no matter the current speed is.

    Here is a sleep demo of p2.js engine, These instances look not sleeping at the same time.

  • The instances only sleep when they come to rest. The Sleep threshhold determines how long they must be at rest before they Sleep.

  • One thing I cannot seem to find though, and I`m sure I must be missing something obvious, is the ability to 'weld' objects together

    Rojo mentioned this a couple of pages back:

    [quote:31gww74c]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:

  • spongehammer

    Thanks, I saw it in my testing.

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