Search Unity

Runtime building editor (similar to Rust)

Discussion in 'Scripting' started by snacktime, Apr 25, 2015.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Thought I'd run my ideas on how to make this sort of thing to see if anyone else has a better idea.

    The goal is a simple runtime editor that lets players build structures out of building blocks. There are a couple of level editors in the asset store that could be used for this, but I want something purposed just for this.

    This is the basic design I have in mind:

    - All blocks have a length/width that is a multiple of the smallest block size.

    - A 3d grid of box colliders of the smallest size defines the build area. Colliders are triggers.

    - Choose a 'block' from a palette, and then you can mouse over the grid. Use raycasting from the block faces to find the nearest matching collider faces in the grid, and snap the block to the best fit as you mouse around.

    - If a block you are trying to place intersects an already placed block (determined using triggers), don't snap/show it as a valid placement.

    Drawing the grid would be triggered by going into an edit mode. Make the grid large enough so you only have to redraw it when the player moves a fair amount of distance.

    Another approach wouldn't use a 3d grid. It could still support snapping to placed objects, but has the downside of objects not always aligning correctly if you don't build out from a single starting point.

    The second part is making the blocks destructable. I'm primarily focused on how to correctly deconstruct the overall structure without having blocks left unsupported. The simplest approach seems to be just ensuring that a block is connected to another block. A more advanced approach might be having a notion of weight, with a minimum connected surface area being required based on weight.