[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Wed Jan 21, 2015 9:03 pm

R0J0hound wrote:It looks like a bug in the js library itself, so it may take longer for me to debug. If you move the tilemap 1 pixel to the right it works flawlessly, oddly enough.


You have to move it both in the x and y axis one pixel to remove the issue completely. Doesn't seem to matter which direction either.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Wed Jan 21, 2015 9:17 pm

Updated to version 1.6.
Download in first post.

* Fixed: The "Query closest line segment" condition would fail to hit some tiles of a tilemap. See note [1]
* Added: Changing a tilemap with this behavior will now update the collisions. NOTE: If the tilemap also uses C2's included physics behavior then whichever behavior runs first will update, the other won't.
* Change: The "imagepoint" option for attaching joints now attaches to the "origin" if 0 is used and the Center of Mass (COM) if -1 is used. Previously 0 would use the COM. @spongehammer

Note [1]:
@Prominent @mattb
The bug would occur if PointA x was the same as the left or right of the tile, or if PointA y was the same as the top or bottom. Strangely enough the bug is also present in the original c library too.

Also I don't generate the collision polygons for the tilemap. I use the polygons that the tilemap provides, which looks very decent.
Image
If I instead used a polyline instead of boxes there would be the possibility to get stuck inside.
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Wed Jan 21, 2015 9:54 pm

@R0J0hound , ah cool. The way the map polys are organized is interesting- That's a good point about the possibility of objects getting trapped if they were polylines- If anyone really wanted to use lines instead, they could generate that themselves anyway I think.

Any plans for a document or something where all the nuances of the behavior can be found?
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Wed Jan 21, 2015 11:57 pm

An interesting side note: Chipmunk has recently updated to version 7, which has all the pro features built in, and is being released free and open source.

https://chipmunk-physics.net/chipmunkPro.php

Apparently, v7 can take advantage of vector proccessing on mobile (NEON), which can give a huge speedup for physics. Though, a javascript port couldn't take advantage...yet. Here's hoping SIMD.js makes it to crosswalk sometime this year...
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Thu Jan 22, 2015 2:47 am

javascript error!
uncaught error: assertion failed: this addition/removal cannot be done safely during a call to cpSpaceStep() or during a query. Put these calls into a post-step callback.

How do I delete joints on post collide? I get that message when I try to do that. Not sure how to get around it.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jan 22, 2015 4:32 am

getting another error when I try to add a joint

TypeError: Cannot read property 'inst' of undefined
at Exps.jointOtherUID (http://localhost:50000/rojoChipmunkBeta ... js:7921:36)
at ExpNode.eval_object_behavior_exp (http://localhost:50000/expressions.js:333:29)
at Parameter.get_exp (http://localhost:50000/eveng.js:2049:19)
at Condition.run_static (http://localhost:50000/eveng.js:1297:41)
at EventBlock.run (http://localhost:50000/eveng.js:866:46)
at EventSheet.run (http://localhost:50000/eveng.js:224:7)
at Runtime.logic (http://localhost:50000/preview.js:2404:36)
at Runtime.tick (http://localhost:50000/preview.js:2066:8)
at tickFunc (http://localhost:50000/preview.js:629:38)


the object is set to -1 because i'm using layout coordinates(it's set to layout)..
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jan 22, 2015 4:34 am

@Prominent
I do need to make some docs with examples in one spot. It's on my todo.

The chipmunk library won't let you destroy shapes or joints under post collide. You could do the actions after a wait action for now. I'll try to work up something so that's done automatically in the plugin.

Ah, I missed something there with joints. Thanks for the report.

@TiAm
I saw that. There are some nice additions for sure. I may try my hand at updating the js port to include them. That vector processing stuff likely isn't usuable though.
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Thu Jan 22, 2015 7:57 pm

Updated to version 1.7.
Download link in first post.

* Fixed: Crash with jointOtherUID expression when joint was connected to world (-1).
* Fixed: "On pre step" and "On post collide" would crash if physics objects or joints were added and removed in the condition.
* Added: "area" expression now works with tilemaps
* Change: Tilemaps now use the "Collision Shape" property. They now support None, box and polygon. Circle and segment will be treated like none.
* Change: "Set collision shape" action works with tilemaps as per the above.
* Fix/optimization: Chipmunk objects will not needlessly update shapes if disabled.

@Prominent
Thanks for the bug reports as always.

-cheers
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Thu Jan 22, 2015 10:18 pm

got this error when I tried opening construct..
can;t open project now since the behavior doesn't load.

---------------------------
HTML5 exporter
---------------------------
Unable to load behavior in 'C:\Program Files\Construct 2\exporters\html5\behaviors\rojoChipmunk\': Javascript exception in file 'edittime.js' line 171: SyntaxError: Unexpected string

Code line:
or Polygon. Circle and Segment are the same as None with tilemaps."", "setCol

Stack trace:
SyntaxError: Unexpected string

This behavior will not be available in the editor.
---------------------------
OK
---------------------------

if I remove the extra " it works.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jan 22, 2015 11:06 pm

also, here's an error I get when I try to add a joint on post collide:

TypeError: Cannot set property 'tag' of undefined
at Acts.addPinJoint (http://localhost:50000/rojoChipmunkBeta ... js:7566:13)
at Action.run_object (http://localhost:50000/eveng.js:1839:10)
at EventBlock.run_actions_and_subevents (http://localhost:50000/eveng.js:929:38)
at EventBlock.run (http://localhost:50000/eveng.js:886:9)
at EventBlock.run_subevents (http://localhost:50000/eveng.js:994:11)
at EventBlock.run_actions_and_subevents (http://localhost:50000/eveng.js:933:8)
at EventBlock.run (http://localhost:50000/eveng.js:886:9)
at Runtime.executeSingleTrigger (http://localhost:50000/preview.js:4565:10)
at Runtime.triggerOnSheetForTypeName (http://localhost:50000/preview.js:4484:16)
at Runtime.triggerOnSheet (http://localhost:50000/preview.js:4416:13)
at Runtime.trigger (http://localhost:50000/preview.js:4393:12)
at mypostSolve [as postSolve] (http://localhost:50000/rojoChipmunkBeta ... js:6441:12)
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests