## Build a global collision object

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Refpeuk
Citizen
Posts: 91
Joined: Wed Dec 14, 2011 6:16 pm

### Build a global collision object

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!
It was the best of times, it was the worst of times . . .

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: Build a global collision object

I'm not quite sure I understand what you want to achieve. Could you rephrase your question? A simple sketch might also help.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Refpeuk
Citizen
Posts: 91
Joined: Wed Dec 14, 2011 6:16 pm

### Re: Build a global collision object

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!

It was the best of times, it was the worst of times . . .

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: Build a global collision object

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 802 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.

hump | HC | SUIT | moonshine

Refpeuk
Citizen
Posts: 91
Joined: Wed Dec 14, 2011 6:16 pm

### Re: Build a global collision object

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 . . .

### Who is online

Users browsing this forum: No registered users and 17 guests