[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Sun Jun 21, 2015 10:23 pm

@prominent
I forget exactly where. Search for "poly" in the runtime.js for how I accessed it. It was basically mirroring what the built in physics behavior does. They both use some helper functions that are defined in commonjs.js. (I think that's the file, it's in the exporters/html5 folder).

The functions allow you to get a list of the points that make up the collision polygon, but transformed to match layout coordinants. The sprite behavior may be another place to find the list of points.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Jun 22, 2015 12:21 am

@R0j0hound , I managed to create a behavior to get nearest polygon point coordinates. The problem I have now is that it isn't correct position if it is retrieved during on post collision in the chipmunk behavior. If I have an object rotating and moving the coordinate is off (maybe it is from the previous game cycle?)..
Any suggestions on how to apply the correct offsets to get the correct position when a collision happens?
B
43
S
19
G
65
Posts: 1,104
Reputation: 37,945

Post » Mon Jun 22, 2015 1:58 am

@Prominent
Yeah, it looks like it's from the previous position. You can try adding these two lines to line#6528 :
binstA.updateC2(binstA.body);
binstB.updateC2(binstB.body);

That should update the c2 object from it's physics body. I haven't tested it, so I don't know if it has any other side effects, because usually it's only done at the end of the tick. Looking at the function it may but I don't have the time to really analyze and debug it.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Jun 22, 2015 4:41 am

@R0j0hound , Thanks! that seems to help. The positions are more synced now, so now my events are working more like how I expect them to. I'll let you know if I run into any side-effects.
B
43
S
19
G
65
Posts: 1,104
Reputation: 37,945

Post » Mon Jun 22, 2015 4:51 pm

Oh my god,
This plugin is absolutely godly.
I had been using the default box2d plugin in my project and thought it would be not worth the hassle replacing it with this Chipmunk plugin.
Well, I done it anyway. And...DAYMN. I need to get measurements, it has improved the FPS dramatically. Not to mention the collision system is much more suited for my project.
Thank you so much @R0J0hound
B
51
S
20
G
10
Posts: 571
Reputation: 9,819


Post » Fri Jul 03, 2015 11:10 am

@R0J0hound Is there a way to use multiple collision groups with one object? Let's say I want that object A does not collide with objects B and C but collide width D and F. In the chipmunk doc I found that it's possible to set multiple collision groups on one object, but in C2 plugin I can't find the way to achieve that.
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Fri Jul 03, 2015 12:40 pm

@xoros - you want the Collision Layers property for the behavior to do that. It takes 8 hexadecimal digits to give you 32 possible layers, but I just use 0's & 1's, giving me 8 collision layers.

In your example, this is how I'd set up collision layers for each object:

10000000 - A
01000000 - B
01000000 - C
11000000 - D
11000000 - F

So you can see each column in the matrix is a layer, & any two objects in a column sharing a 1 will collide.

Here's a more complex example where A doesn't collide with B & C, but collides with D & F.
B doesn't collide with C or D, but does with F.
C collides with D, but not B or F.
D collides with A, F & C but not B.
F collides with A, B & D but not C.

10000000 - A
01000000 - B
00100000 - C
10100000 - D
11000000 - F

Then you could extend this by giving all instances of a particular object a Collision Group number (which is just a single integer). Objects with the same non-zero group number won't collide.

This is handy if say object F is physics debris & doesn't need to collide with other F's for performance reasons.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Fri Jul 03, 2015 1:45 pm

@mattb thanks for explantion
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Mon Jul 06, 2015 3:54 pm

Had a go at making some dynamic smoke for a stealth game, the idea being that it can block LOS or laser raycasts & triggers smoke detectors...

https://dl.dropboxusercontent.com/u/523 ... _test.capx
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 5 guests