I'm designing a game (my first in Construct 2!) for Ludum Dare 28 where the central element is that the player can add parts they salvage onto their vehicle. I've tried two different approaches now, and the current one is more clean and takes advantage of families, but it still doesn't work completely.
The intended behavior is:
1) When player collides with armor, mount (pin) the armor to the player (directly under it).
2) When armor collides with other Armor, snap/align the other armor and pin to existing armor.
3) [not implemented] When armor collides with a cannon, pin the cannon directly on top of the armor. (Same for anything else in the Mountable family)
<img src="http://crossbreadtech.com/imageserver/pin-and-collision-events.png" border="0">
Right now #1 works. For some reason, the collision between two armors only works for the first layer (adjacent to the player, and armor it's mounted to.) Even then it inconsistently snaps to the wrong (not nearest) image point. Also the first collision seems to be ignored, but on a second pass it picks up the block.
I'm pretty stumped and have been staring at this literally all day, read tutorials, the manual, googled, etc. Learned a fair amount, but I still can't figure out what the problem is here.
The green squares are spawned on top of any non-zero image points of the armor so that I can use pick nearest. They store the image point they were spawned on so that I can then move the new part to that location and pin it to the player.
The Buildable and BuildableOther families are mainly to facilitate performing specific actions on the two armor sprites when they collide.
Another element of the game is that you have to fight yourself (Pressing R should build a copy of you) although I'm pretty sure that's broken after I ripped out my first attempt. To do this, I was recording the type and X/Y distance from the Player for every part added in 3 arrays, type, X, and Y.
The problem with this is that if the player was turned sideways, the coords could be off, so reconstructing the clone didn't work unless I locked down the player's freedom to rotate. I had considered using relative polar coordinates instead, capturing angle relative to the player, distance, and type. But if there is a better way to do this I'd love to hear it.
Here's the live version if you want to see what I'm talking about.
I'm super impressed with how helpful this community is, so thanks in advance!