Page 11 of 66

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Wed Jan 21, 2015 9:03 pm
by Prominent
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.

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Wed Jan 21, 2015 9:17 pm
by R0J0hound
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.
If I instead used a polyline instead of boxes there would be the possibility to get stuck inside.

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Wed Jan 21, 2015 9:54 pm
by Prominent
@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?

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Wed Jan 21, 2015 11:57 pm
by TiAm
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.

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...

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Thu Jan 22, 2015 2:47 am
by Prominent
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.

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Thu Jan 22, 2015 4:32 am
by Prominent
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 (http://localhost:50000/eveng.js:866:46)
at (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)..

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Thu Jan 22, 2015 4:34 am
by R0J0hound
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.

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.

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Thu Jan 22, 2015 7:57 pm
by R0J0hound
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.

Thanks for the bug reports as always.


Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Thu Jan 22, 2015 10:18 pm
by Prominent
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.

if I remove the extra " it works.

Re: [BEHAVIOR] Chipmunk Physics

PostPosted: Thu Jan 22, 2015 11:06 pm
by Prominent
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 (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 (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)