[beh] Box2d+ (2.3.0 emscripten) [update: 2017-11-18]

0 favourites
From the Asset Store
Pack of illustrator graphic styles. Make your own logos, game titles, or anything you want.
  • Box2d+

    This is an ongoing project to port the emscripten/asm.js version of Box2d v2.3.0 to Construct 2. The performance is amazing - more stable than Chipmunk and much more stable than the standard asm.js physics. Plus there are some useful game-dev friendly features. It is easy for a beginner to use but powerful enough to keep the more experienced happy. At least, that's the plan. Of note, it doesn't play nicely with the standard physics plugin and will cause your browser to vanish into a singularity if both are used in the same project (the emscripten libraries interfere at runtime).

    There main demo has 4 parts:

    1. The start screen gives you an idea of performance and demonstrates one-event conveyor belts with kinematic bodies. Collision points and polygons can be selected to be drawn and objects can be thrown around.

    2. Bitmap / scan image. This is a demo with 2 objects - one fixed and one that will be re-spawned; when running, both types can be dragged. You can use the default images or upload your own into the demo. When you press Start the engine will scan the images and assign collision polygons from the image alpha.

    3. Stress test. A comparison with Chipmunk (which, from my previous testing, is the best non-emscripten physics library in JavaScript) and the standard asm.js physics behavior. The test creates a pyramid of boxes that you can interact with or just watch collapse....

    4. Draw objects. Draw some physics shapes, convex or concave, and watch them fall down. The shape vertices are stored in a c2 array which is loaded into the Box2D+ plugin to form the collision polygon.

    Here's the demo (v1.0.1.8): link

    Summary of features:

    Plugin features already completed:

    Scan image to create polygon from its alpha (uses adjusted versions of hull.js and simplify.js)

    Circle, polygon and box shapes

    Speed clamp

    Rotational speed clamp

    Collision point

    Dynamic, Static and Kinematic bodies

    Collision filtering (category and mask bits)

    Object gravity scale

    World x and y gravity values

    Load collision hull from c2 json array

    Get collision hull as c2 json array (create polygons outside your game and upload from string)

    Raycast world queries

    Assimilate Joint - demo: link

    All joints are demo'd here: link

    AABB world queries (find objects in a defined box area)

    Gravity attractor

    Polygon editor capx (demo: link)

    Platformer behavior capx. Demo (with one-way doors/floors and wall-climb): link


    More joint helper expressions added

    Obtain collision impulse and collision impulse angle*

    Obtain pre-collision and post-collision velocity (x and y values)*

    Collision Pre-Solve trigger and an action to disable the collision.*

    Features to do:

    A platform behavior helper plugin, so you won't need to mess with complicated events to control the movement and doors etc.

    The test is just about finished....!

    Ideas and suggestions are welcome.

    Not included / what's been excluded:

    Mouse joint (no need, better done using events and hidden object).

    Friction joint.

    Rope joint. The box2d rope joint stretches and breaks far too easily to be useful. Work-around: use revolute joints.

    *latest changes

  • Сool, it is better than asm.js physics! I'll follow your work!

  • Thanks radbrothers!

    Update to the WIP plugin and the demo: Now added raycast. Left click/drag to draw a raycast line.

  • Awesome work! look forward to updates

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Awesome work! look forward to updates

    Thank you

    Here you go: I've managed to get some joints to work!! Just some tweaking now, then I'll create a joint demo.

    Joints now working:

    Revolute / Limited Revolute / Revolute motor / Gear on revolute







    Joints not planned for inclusion:

    Mouse joint (no need, better done using events and hidden object)

    Friction joint

  • this looks very promising, tell me you have some alpha/beta for people to use!

  • this looks very promising, tell me you have some alpha/beta for people to use!

    Thanks! Not yet - I'm still trying to add features. But when I do I will announce it.

    New feature added - a c2 bespoke "Assimilate" joint. The weld joint suffers from the same problem that all physics library 'fixed' types of joints suffer from - because the engine iterates over each object in turn, the joints aren't truly solid because each object exerts slightly incorrect forces onto the others they are joined to. And lots of joints between lots of objects can cause joint fighting (it's spectacular, but frustrating).

    The cure: object assimilation. In this Box2d+ plugin you can assimilate an object as the child of another (in box2d language, you turn it into a fixture) - and back again, of course. Here's an example:

    *The cpu should read ~12%. I've been mixing up my c2 with my javascript...

    Try it out for yourselves: link

    Left mouse to drag, right click anywhere to toggle assimilate joints to join all of the icon squares to the round object.

  • Try it out for yourselves: link

    Amazing, im interested in the collisions only which is much faster and correct than i ever experienced with C2.

    Hope you can finish this! Keep at it! il buy it even if its premium released!

    The cpu utilisation is a bit high for 200 objects (maybe because is still a WIP? or that isn't the cpu in real time? i see 1% being stuck there.) usually those objects use around 0.02% on my pc.

  • - Thank you!!

  • Alrighty... Putting together the demos highlighted a limitation to how events work for this plugin. For example, on a collision trigger, if you want to use an Action on the object that was hit (not the one with the trigger condition) then you have to sort through the other box2d objects and identify the one associated with the uid obtained from the collision. You can get around this to some extent by using families, but that method can get complicated when filtering.

    So I'm going to make all Actions in this plugin 'global'. There will be a uid field that'll be auto-populated with Self.uid but you will be able to over type it if you wish to pick another object instead.

    If you think this is a crazy idea, please let me know now before I change too much! Thanks

  • Nice work! Really impressed with the look of this - should solve a lot of physics issues I was running into. Are you planning on also releasing a C3 version?

  • I tried the stress test to compare the 3, but didn't notice any major difference.

    All 3 peaked around 90% cpu and dipped to around 30 fps. I think the Asm was the smoothest/snappiest of the 3. Chipmunk seemed slowest but perhaps more sensitive due to more collision points being shown? So maybe it is performing more steps than the others?

    Anyways, it is nice to see another option available! I'll be interested in trying it out.

  • mekonbekon - thanks! Once I get this stable and c3 is out of beta then I'm planning on making a c3 port. But that'll be a long way off, I think.

    Prominent - Interesting. On my i5 laptop the old asm.js was pretty good up to 35 layers, then it would bulge and deform. Chipmunk would fall apart by itself, but my version ob box2d would be rock steady. I guess you're using a more powerful computer, so the stress is less stressful..?

  • No, I'm using a 9 year old laptop with core 2 duo. The asm version had some sagging, but it felt quickest (maybe it is less precise).

  • Now added a joints demo link. I'm discontinuing the rope joint because it's terribly inconsistent (often breaks and stretches). The revolute joint is far more reliable for making ropes and there's an example in the link to show this.

    Next on the todo list:

    Gravity attractor

    Tidy up code

    Make hull from image editor

    Make platform behavior (using events, so it can be user-adjusted).

    Start work on instruction manual

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