[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Tue Sep 22, 2015 9:51 pm

Here's an example that might be handy for anyone making a physics platformer using Chipmunk. It's something I made to try out puzzle mechanics & has a few issues, but it might be worth dissecting to see eg. how 1-way collisions are now possible after rojo's update last week:

https://dl.dropboxusercontent.com/u/523 ... pe_v2.capx

EDIT - tweaked movement to be more like the stock platform behavior
Last edited by mattb on Mon Oct 05, 2015 12:44 pm, edited 1 time in total.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Sat Oct 03, 2015 12:53 pm

R0J0hound wrote:You shouldn't need to use dt anywhere. A fixed timestep of 1/30 is the timestep used per frame. So if the game is running at 60fps then after 60 frames the physics will be 2 seconds along compared to the actual 1 second.

You can specify a variable timestep but that isn't so good with physics, so a fixed timestep is recommended. The drawback is the physics can run faster/slower depending on the screen refresh rate, aka it's not framerate independent. That said you could detect the fps of the game when it starts and set the timestep based on that.


Do I understand this correctly.
If i set my game/level to start with

On start of layout
Stepping mode - Fixed
Fixed timestep - 1/fps

The physics will run at same speed on screens with different refresh rates?

If I leave it at the standard 1/30 does that mean someone with higher fps can finish the level faster?
B
15
S
3
G
3
Posts: 93
Reputation: 1,466

Post » Sat Oct 03, 2015 5:52 pm

@Giganten
It should, although I'm not sure if "fps" will have a good value at that point. You could wait a second or so first first.
Just leaving the timestep at 1/30 means if the refresh rate is 120 the physics will run twice as fast than if the refresh rate were 60.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Sat Oct 03, 2015 6:11 pm

Isn't the monitor refresh rate different than fps?

"FPS = Frames per Second = How many distinct images a GPU outputs, per second
Refresh Rate = Number of times a screen is capable of DISPLAYING, per second"

Shouldn't the physics simulation run exactly the same if both are running at 60fps, except one monitor is 60Hz while another is 120Hz?
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Sat Oct 03, 2015 6:26 pm

@Prominent
It's the same as far as I know. The browser could cap the fps, but I don't know since I've only ever used 60hz displays.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Sun Oct 04, 2015 4:52 am

I found an error:
I get assertion failed: internal error: attempting to set body's angle to NaN: line 52 col 3.
When I tried to add a dampened rotary joint between to physics objects.
Both objects had their rotation disabled. I enabled one object's rotation and the error went away.. So maybe it doesn't need fixing since having a rotary joint between objects that shouldn't rotate wouldn't make sense anyways.
Thought I would mention it though.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Sun Oct 11, 2015 9:10 am

@R0J0hound , Is there a way to pick a joint based on its index?
For example, I want to loop from 0 to (Chipmunk.jointCount-1), and then pick an object by uid based on Chipmunk.jointOtherUID(loopindex). I tried this, and doesn't seem to work.
I don't really want to have to store a list of joints an object has if I could just cycle through them based on their index.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Sun Oct 11, 2015 10:40 am

@prominent
That should work. I'll have to look at it tomorrow to see why it doesn't.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Sun Oct 11, 2015 6:24 pm

@R0J0hound ,
here is a capx showing the problem in a simple scenario.
edit: here's a new capx: http://1drv.ms/1R5XwJ6

edit: it seems to not work if it is inside a post-collide. It works outside of it though. I need a way to do it inside the post-collide- I'm assuming it is a bug?

edit2: also, I just noticed in this case it adds the joint twice since the collision events run for both objects that collide.. If I try to add a condition to check if a joint was added(so that it won't add another), it won't find that joint so it will add the extra joint anyways. I think this is related to the joints being updated at the end of the event cycle. If there were a way to update the joint list sooner or something, it would make things easier to manage.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Mon Oct 12, 2015 5:49 am

@Prominent
It only doesn't work for joints that were just added in a post collide. It has to do with chipmunk not allowing anything to be added or removed during a pre or post collide, so instead the plugin delays it slightly. The unfortunate drawback is it causes a lot of bugs related to stuff just added in those triggers.

I don't have a simple fix for it, so it's an open issue for now.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest