Detecting Neighbor Ship Parts

When I place down a ship part I need to connect them together. To do this I simply test for any overlaps from a circle collider. You can do this easily with the following code:

Collider2D[] colliders = Physics2D.OverlapCircleAll (transform.position, .1f);

Here is what it looks like when I place down a new ship part and the PartEditor script auto detects any neighbor parts.

ship-editor-1

And here is a mockup in the Scene editor to show what the circle collider would look like in the game and you can see the overlaps on the top, right, bottom and left sides where I test for collision.

ship-editor-2

Now I need to save out the connections and also nest the new part inside of the ship GameObject.

Subscribe To My Mailing List

Want to learn how to make a game? Not sure where to start? Even if you are a seasoned game maker there is still a lot you can learn from my mailing list. I'll be covering tips and tricks for how to build, release and market games each month.

Simply sign up for my mailing list and also get access to a 50% off discount code for my eBooks and other content. I promise to not spam your inbox!

Join Now