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:
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 (12.98 KiB) Viewed 555 times
It was the best of times, it was the worst of times . . .
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 (30.93 KiB) Viewed 2950 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
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.
It was the best of times, it was the worst of times . . .