So I've been playing around with chipmunk for while now and I'm really enjoying it! I'm building a 2d side-scrolling, tile-based platformer and have run into the problems that other people have with the character bouncing around on the "gaps" between the tiles. Similar to this thread: http://chipmunk-physics.net/forum/viewtopic.php?t=1377
I understand chipmunk isn't really meant to handle this situation but I had an idea that I thought I'd run by people more familiar with the library.
I'm already using slembcke's "Your Story" style platforming velocity function (see here: http://chipmunk-physics.net/forum/viewtopic.php?t=1932) for controlling my character. Along the same lines, can I remove my tiles from the chipmunk simulation and instead hook my own code into the collision system to do tile collision manually? The idea being that all dynamic bodies are handled by chipmunk, but I manually check for collisions against my static tiles and inject the proper resolution?
Does that make sense? Am I just better off writing the physics side myself and abandoning chipmunk?
Using Chipmunk with 2d Tiles
-
- Posts: 3
- Joined: Fri Sep 14, 2012 7:52 am
- Contact:
-
- Posts: 24
- Joined: Wed Mar 16, 2011 12:17 pm
- Contact:
Re: Using Chipmunk with 2d Tiles
You could merge simple box shapes to one greater shape. I ran into it some time ago, see here:
http://chipmunk-physics.net/forum/viewt ... =collision
In the last post you can see what I mean.
http://chipmunk-physics.net/forum/viewt ... =collision
In the last post you can see what I mean.
-
- Posts: 3
- Joined: Fri Sep 14, 2012 7:52 am
- Contact:
Re: Using Chipmunk with 2d Tiles
Thanks gnasen, I considered building composite shapes out of the tiles, my only worry is performance. To start, I was trying to duplicate tile based digging and building a la Terraria and the other 2d diggers. If I allow adding and removing tiles arbitrarily by the player, I'd need to be able to do this at runtime and my guess is that it may not be fast enough to handle that well.
Do you support modifying the terrain at runtime or is it a pre-process?
*Edit: I think I'm going to attempt some simple horizontal and vertical strip generation. I may be able to write it in a way to make re-generation not too difficult. I'll let you know how it goes.
Do you support modifying the terrain at runtime or is it a pre-process?
*Edit: I think I'm going to attempt some simple horizontal and vertical strip generation. I may be able to write it in a way to make re-generation not too difficult. I'll let you know how it goes.
-
- Posts: 3
- Joined: Fri Sep 14, 2012 7:52 am
- Contact:
Re: Using Chipmunk with 2d Tiles
Success! I went ahead and took gnasen's recommendation and created outlines for all of my tile clusters. I decided to simplify the process by simply generating horizontal and vertical segment shapes instead of poly shapes for each connected component. This should make updating the collision shapes pretty straight forward at runtime. The algorithm for building it initially is pretty straightforward - just scan horizontally looking for exposed tops and bottoms of the tile, then another vertical scan for exposed sides. Not worrying about connecting the segments makes it much simpler to work with.
I figure if I need to deal with collision callbacks for specific tiles I can either figure out the tile based on the position it collided on the segment, or just enter sensor shapes for every tile. Anyway, here's a little screenshot of it working (ignore the temp art I grabbed off of a google search ):
I figure if I need to deal with collision callbacks for specific tiles I can either figure out the tile based on the position it collided on the segment, or just enter sensor shapes for every tile. Anyway, here's a little screenshot of it working (ignore the temp art I grabbed off of a google search ):
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Using Chipmunk with 2d Tiles
Very nice.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 14 guests