[beh] Box2d+ (2.3.0 emscripten) [update: 2017-10-09]

Post your work in progress addons and get feedback

Post » Mon Sep 11, 2017 9:36 pm

Image

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.

Image


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.

Image


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
Instructions!
More joint helper expressions added*


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:
Collision PreSolve and PostSolve callbacks. These proved to be extremely expensive. Work-around: use collision filters to disable collisions, track object velocity to measure collision impulse.
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
Last edited by Colludium on Mon Oct 09, 2017 9:47 am, edited 16 times in total.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Tue Sep 12, 2017 8:31 am

Сool, it is better than asm.js physics! I'll follow your work!
B
12
S
3
Posts: 116
Reputation: 1,436

Post » Tue Sep 12, 2017 7:40 pm

Thanks @radbrothers!

Update to the WIP plugin and the demo: Now added raycast. Left click/drag to draw a raycast line.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Sat Sep 16, 2017 4:32 am

Awesome work! look forward to updates
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Sat Sep 16, 2017 5:11 pm

justifun wrote: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
Prismatic
Distance
Pulley
Weld
Rope
Wheel

Joints not planned for inclusion:
Mouse joint (no need, better done using events and hidden object)
Friction joint
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Tue Sep 19, 2017 3:58 am

this looks very promising, tell me you have some alpha/beta for people to use!
B
78
S
23
G
69
Posts: 1,353
Reputation: 43,985

Post » Tue Sep 19, 2017 6:19 pm

gamecorpstudio wrote: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:

Image
*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.
Last edited by Colludium on Tue Sep 19, 2017 7:49 pm, edited 1 time in total.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Tue Sep 19, 2017 6:24 pm

Colludium wrote:
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! :D 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.
Last edited by gamecorpstudio on Tue Sep 19, 2017 6:27 pm, edited 3 times in total.
B
78
S
23
G
69
Posts: 1,353
Reputation: 43,985

Post » Tue Sep 19, 2017 6:25 pm

@gamecorpstudio - Thank you!! :)
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Fri Sep 22, 2017 10:46 am

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 :)
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Next

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 1 guest