Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

help building an attachment system for multiple objects

Discussion in 'Scripting' started by MastaPlatypus, May 14, 2020.

  1. MastaPlatypus

    MastaPlatypus

    Joined:
    Apr 16, 2019
    Posts:
    4
    heyo!
    i'm recently trying my hand with unity by making a game about space stations and i have a question:
    as the title says the objective is to give the player the ability to build the stations piece by piece, in a modular way, but i'm not sure how should i approach the "docking" procedure.
    i would like each station module to be able to be attached to eachother by childing itself to the module it's being docked to and my first idea was to add a trigger collider to each docking port so that when they get under a specific distance this would happen.
    my problem with this tho is that if i make an universal "docking port" prefab when two get into contact they would both try to child themselves to one another and im guessing that would be trouble, making two separate prefabs (like a "master" and "slave" port) woudnt work either because i cant say beforehand wich orientation/side a player will be trying to to dock them.
    do you guys have any suggestion on how shoud i try to do this? thanks in advance for the help!
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    I would give each dockable piece a sequential id when it is created. When they dock, always pick the lower number to be the parent and the higher number to be the child.