Detecting Orphaned Parts

Detecting Orphaned Parts

Work continues on my ship editor. Tonight I finally decided to roll up my sleeves and sort out the logic for being able to detect when parts are no longer attached to the center of the ship. Here you can see how this works (ignore the strange issues with the selection boxes not updating correctly, it works but the gif capture messed it up): I had originally thought about using A* to detect if each part could draw a connection back to the center but that ended up being a total mess. The way I do it now is that each part has an array of parts it’s connected to. You can call Connected() on a part and it will loop through it’s neighbors and flag that they are connected. This ends up being recursive and when it’s done I simply loop through all the parts and if they are no longer connected I change their material’s color to red. Now I can start working on the part inventory to handle creating different ship parts as well as where parts go when you delete...
Fixed Ship Builder Selection

Fixed Ship Builder Selection

The ship builder will now only let you add new parts to open areas around the currently selected part. It also removes the last selection areas where a part was just placed. Here is the updated builder in action: Now that I have the underlying logic for connecting parts together everything else for the UI will come together a lot quicker...
Ship Builder Up And Running

Ship Builder Up And Running

It’s still super basic but the ship builder is now working. Here is a demo of what it looks like in action: When you place a part down, the editor now links each node up so I can keep track of what open slots (top, right, bottom and left) are taken: Next up is making sure you only see the editor for open parts of the ship before I move onto wiring up the logic for deleting parts and validating the connected ones are still attached to the main ship...
Detecting Neighbor Ship Parts

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. 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. Now I need to save out the connections and also nest the new part inside of the ship...
Basic Ship Edit Mode

Basic Ship Edit Mode

The ship builder is coming along. I now have selecting a ship part in place as well as highlighting where you can place a new part. Here is what it looks like when you enter edit mode: From here I can connect up the logic to place a new parts, rotate them and set up the connection...
Breaking Off Ship Parts

Breaking Off Ship Parts

I learned a neat trick today in Unity. If you set the transform.parent to null you can un-nest GameObjects. That means it’s super easy for me to start testing out how to break off pieces of the ship in my new game. I also found a new animated gif screen recorder for mac called GifGrabber so here is what the effect looks...

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