Chipmunk2D Physics demo

Video

Download:
Chipmunk2DTest.pdx.zip (141.2 KB)

A quick toy I made using Chipmunk2D physics (https://chipmunk-physics.net)

No real plans to do more to this - I was just interested to see if I could get the physics library working on the Playdate.

15 Likes

Thats' really cool.

I was hoping someone would do some work on a physics engine so thank you for doing that. :slight_smile:

Right now it's all C right?

Yep, all C. I'm sure it's possible to make some nice Lua bindings, but that's beyond me at the moment.

Did you run this on device? What is FPS? I spent a lot of time working with physics on Lua and faced the impossibility of normal implementation due to the low performance of the device.

For example: everything is great in the simulator
but on the device after 5 objects the frame rate drops to 1 :frowning:
2

I tried the demo on my device. 22-25 fps. This is a great result!

1 Like

Yeah, I was impressed. Not sure if tweaking some settings could improve things further. (I didn't write the physics library - just made a few modifications to get it working on the Playdate.)

I've attached the source if anyone's curious, but it definitely shouldn't be used for anything important - much better to download the official Chipmunk2D library and make the few required changes to get it working on the Playdate.

Source only (567.2 KB)

1 Like

Missed this, but totally awesome!

I am confident that if drawing to the screen was optimised to only draw changed pixels each update then the increase in framerate would be huge. Drawing the whole screen every update automatically limits you to ~30fps and everything on top of that will decrease it further.

Hello! I'm doing exactly what you mentioned here, trying to get a (C only) playdate project up and running using the chipmunk physics library. I'm on Windows, attempting to use a visual studio solution. After a bit of trial and error I am now able to generate a visual studio solution that includes chipmunk source files, and my game's c source files. However I'm running into trouble compiling the project. first up, I get an error on line 561 of cpPolyline.c, it doesn't like the "struct Notch notch = {};" syntax. if I comment out the "{}" it compiles, but now I get a cryptic error about the command "setlocal" failing, without much into.

I'm wondering if you have any guidance on the changes you made to get your demo compiling?

well, as is usual the case, once I post about an issue I find a solution. I did have to change the syntax of line 561 as I mentioned above, but the "setlocal" issue was related to having the simulator open with an old build of my project .pdx opened when I attempted to make a new build. I think it fails because it can't delete the old build since it's in use by the simulator.

closing the simulator and building worked!

Did you ever get the chipmunk2d code running on the device? When I run it on the simulator it runs fine, but when I run it on the device it instantly crashes

I did get Chipmunk working on device, although honestly it was so long ago now I don't remember what issues I ran into and how I overcame them :blush:

Hello @maximile

Just wanted to drop by and give my thanks for the proof of concept you posted back in 2020 here!

I used this toy project as a starting point to get a (mostly) working build of Chipmunk physics which I could then use to build up my pachinko game Cascada, which just released this week.

If it is of use to anyone else, this game open source and you can find it here: GitHub - timboe/Cascada: Prototype playdate physics game, working title

I found Chipmunk to be great for this style of game on Playdate, the collisions are primarily between a small number of balls and the level's obstacles. With the obstacles themselves not requiring any self-interaction.

Hence I can get 100+ obstacles in a level and maintain both 50 frames per second and 50 physics ticks per second. And that's after subtracting the CPU required for full-screen rendering at 50 FPS.

Thanks for sharing!

Note that dynamic objects are the ones that are demanding. Those are the ones that are fully simulated. The ball(s) in this game. I estimate the max amount you can have in the scene to be around 15. Perhaps a few more if they are not simultaneously moving. (note! the "sleep" feature that detects and disregards dynamic objects that have settled is disabled by default in Chipmunk2D)

My experience has also been that you can add an infinite number of static objects and quite a few kinematic objects (objects whose movement are controlled by code; for examples obstacles that move along a path)

The Godot editor is a nice idea. With Wheelsprung I struggled and failed to find a platform to create a web based editor that is usable by players without installing software.

1 Like

Hi @Nino

Yes that's right, I haven't currently generalise the code over N balls, so have only ever tried with up to two so far.

And I now listened to the recent podcast episodes, so Wheelsprung is Chipmunk too :smiley: two chipmunk-driben games with level editors within around one week!

I see I have an optimisation left to apply though. At the moment all my obstacles are kinematic, even the ones I that don't go on to move. I could split these up into kinematic for the ones which move & static for the ones which don't. I expect then that this should let me go beyond ~100 obstacles. Not that I need to go beyond 100, the playing area is already very full by this point...

For the editor, the godot based editor was a bit of work to get setup, but design freedom was a big plus. It's also rather hacked together, it just copies the game's motion-path logic for rendering moving obstacles. I didn't integrate godot's physics engine so you can't currently test levels in the editor.

1 Like

You'll notice the difference between kinematic and static objects for sure, go for it.

2 Likes