[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Tue Jun 21, 2016 5:25 pm

I know, you probably don't have much time to fix stuff with this plugin @R0J0hound , but thought I would mention that if I have chipmunk objects on two separate layers, and one layer has a different angle set, objects only use the angle of the layer they are currently on.
So when colliding, the layer angle isn't taken into account if the object they're colliding with is on a different layer.
Hope that makes sense.
I test this with tilemap on a rotated layer, and an object on another non-rotated layer. Object acts as if tilemap isn't rotated. If the object is put on same layer as tilemap, then it acts as if it is rotated.

Maybe it is a C2 issue?
edit: layer-rotate-tilemap-collision-bug_p1049253?#p1049253
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

Post » Tue Jun 21, 2016 8:09 pm

I'm curious to know what are some of the best ways/tips to try optimize a project using this behavior? I'm working on a game for a limited hardware and although the performance is better than with C2 standard physics I could still use some helpful advice to improve the framerate further. Obviously I'm trying to keep the object count low and in check, I've also experimented with idle/sleep time threshold values but other than that what steps could I take to optimize further?

Also, I'm trying to add some bouncing objects into the project but was wondering what's the correct way to do this? Let's say I have a basketball that's supposed to bounce off ground surfaces. I can achieve this by increasing the elasticity value on both the basketball and ground surfaces, but if I want to have the ball also bounce off other objects and increase their elasticity too, these objects will also bounce off the ground surfaces similar to the ball. If I keep the ground surface elasticity low (say 0.2) and instead just increase the ball elasticity to something like 5, they will bounce off the ground as intended, but on collision with other basketballs they are sent flying like a missile:) Any help on what's the recommended way to set this kind of scenario up would be appreciated!
B
32
S
9
G
4
Posts: 132
Reputation: 4,348

Post » Wed Jun 22, 2016 8:04 am

@AnD4D
If it crashes it's a bug, and I think that one is known. I haven't worked on it in a while but the plan was to rework the entire plugin so that's easier to fix. The crash is do to some logic error on my part, but it usually occurs when setting the mass under one of the plugin's trigger or loop events. The reason is under those events the chipmunk library itself won't let you change the mass, collision shape,... etc of an object. To alleviate that the change is just delayed till it's allowed to. In short it introduced too many special cases which made it increasingly hard to debug and fix, so an internal rewrite is needed in order to simplify things. I unfortunately don't have the time or interest to work on plugins to that extent, but at least for the most part this plugin is in a working state.

@Prominent
Yeah, I never investigated handing layers with different parallax, rotations and such. I just left it as unimplemented. Tilemaps can't rotate as I recall, otherwise I would have let them if I could. That bug seems odd, looks like the tilemap's bounding box is being used.

@Waltuo
Usually you'd keep the elasticity in the range of 0 to 1. I'd make the ground and the first ball 1, and the second ball 0.2 or something. When two objects collide their elasticities are multiplied together.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Sun Jun 26, 2016 7:24 pm

Is there a way to limit On Post collide triggers to run once? Sometimes they run more than once due to multiple collisions at the same time(as far as I can tell). I only need to do certain things based on the last collision, so when it run more than once, it makes errors.

edit: okay.. seems I figured out the issue:
I had a condition Sprite.Chipmunk.jointType("Tag")="" in the on post collide. And I was adding the joint in the event, however, it seems it doesn't add it immediately or something.
I changed it to rely on an instance variable instead, and that fixed the issue.
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

Post » Sun Jun 26, 2016 9:18 pm

A quick way would be to use a variable like this:

Code: Select all
global variable once=0

on collision
once=0
--- set once to 1
--- do stuff

every tick
--- set once to 0


That way you'd only get one event per tick on that object type. Actually you'd want an instance variable instead to have one collision per instance per tick. Or if you wanted only one trigger per pair of instances you could use a dictionary to keep track of it like:

Code: Select all
on collision
X dictionary: key exists min(sprite.uid, sprite.chipmunk.otherUID)&":"&max(sprite.uid, sprite.chipmunk.otherUID)
--- dictionary: add key min(sprite.uid, sprite.chipmunk.otherUID)&":"&max(sprite.uid, sprite.chipmunk.otherUID)
--- do stuff

every tick
--- dictionary: clear


I do not know if the chipmunk library has anything to help with that.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Sun Jun 26, 2016 9:47 pm

Thanks, that dictionary method looks useful- i'll have to remember that if I need to check pairs.
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

Post » Mon Jun 27, 2016 1:11 am

Any way to change friction/elasticity per collision? I'm trying to get a collision response to make an object bounce without friction, and then set it back so that other objects keep their friction/elasticity when they collide.
I also tried calculating my own response by reflecting across normal, etc, but it doesn't work.

edit: I got the reflecting working, but the friction still gets applied. I can't find a way to turn off the friction during a collision.
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

Post » Mon Jun 27, 2016 7:46 am

alright, this seems to work:
Image
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

Post » Wed Jun 29, 2016 1:10 am

edit: figured it out- tilemap was set to box instead of poly.. not the polygons are working per tile.
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

Post » Wed Jun 29, 2016 5:30 am

Apparently you can't collide two segment shapes together??
is this a bug @R0J0hound ?

edit: I checked the chipmunk docs, and apparently segment shapes can't collide with other segment shapes.. I guess I'll have to try and find some alternative.. maybe a thin polygon- I'll try that.

edit: I tried a thin polygon, but I get an error stating that the moment of inertia must be positive and non-zero. line 52 (col 3).
B
43
S
19
G
65
Posts: 1,098
Reputation: 37,933

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: bomt and 3 guests