Page 1 of 1

Build a global collision object

Posted: Tue May 15, 2012 6:39 pm
by Refpeuk
Hi guys,

I have a game where you build a spaceship with a simple editor on a map of square tiles. I then export it into a ship that can fly around in flight mode while controlling someone walking around inside (sort of diabloish control scheme). For the ship-player collisions I just have a square collision object for each tile.

Instead of trying to translate every tile with complex rotations every frame when moving the ship I decided to leave it at origin and draw it to a canvas instead, and move that around. I still need to be able to generate a collision object for the ship to use in the global scheme of things, however, so what I want to be able to do is take my tilemap data and basically "shrink-wrap" it so that I end up with a shape that shows its outline.

I'm using hardoncollider, so basically I need to find all the points in order and add them to a table, then call something like:

Code: Select all

ship[1].shape = worldcollider:addPolygon(unpack(point_table))
Can anyone think of I way I could populate that table with the points in order?

Thanks!

Re: Build a global collision object

Posted: Wed May 16, 2012 1:18 pm
by vrld
I'm not quite sure I understand what you want to achieve. Could you rephrase your question? A simple sketch might also help.

Re: Build a global collision object

Posted: Wed May 16, 2012 9:44 pm
by Refpeuk
Here's a diagram that will hopefully help. I have a 2d array (actually its 3d because the tiles each have more than one property, but that's unimportant) that takes the form of a tilemap, like this, though usually bigger. I want to be able to generate a collision object like the red line.

Thanks for your help!
GRobk.jpeg
GRobk.jpeg (12.98 KiB) Viewed 231 times

Re: Build a global collision object

Posted: Fri May 18, 2012 2:29 pm
by vrld
If your ship hull is always going to be a convex shape and you are satisfied with a collision shape like this one
GRobk.jpg.png
GRobk.jpg.png (30.93 KiB) Viewed 2626 times
you can just compute the convex hull (for example using Graham scan or gift wrapping) of all the edges of the tiles that compose the ship. Otherwise this might be a though problem.

Re: Build a global collision object

Posted: Fri May 18, 2012 4:54 pm
by Refpeuk
Yeah, I wanted as much flexibility as possible, and convex shapes wouldn't be at all uncommon. I do have diagonal tiles, though, so the shape you showed would be ideal for that specific ship. Thanks for the links, I'll take a look at them and see if I can perhaps adjust them to fit my needs.