Search Unity

Runtime Object Placement (like Rust)

Discussion in 'Scripting' started by BlueSin, Feb 13, 2014.

  1. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    I am fairly new to Unity, but getting along pretty quickly. I am already able to make a terrain similar to that of Rust. For those of you that are not familiar with Rust, just think Minecraft but more 3D for now.

    Essentially, I want to know how to allow the player to place objects such as workbenches, furniture, even whole buildings during runtime, and the object should also snap to the terrain. I am sure something like this already exists in the Asset Store, but I cannot seem to find it. I tried googling it as well but I keep finding stuff that is for easy object placement or procedural object placement. Which is not what I need.

    Anybody know what I am talking about and what I need? Have a link?
     
  2. Brotherhood

    Brotherhood

    Joined:
    Dec 8, 2012
    Posts:
    73
    1. Instantiate object, as per usual.
    2. Give your object a sexy semi-transparent green shader.
    3. Adjust the position according to the player's view/cursor/however you want to make placement.
    4. Create a collider that stops the object from clipping through terrain/other objects and which changes your sexy green shade to sexier red.
    5. Shoot ray(s) down from the object's corners and/or centre that detects the ground and adjusts the height accordingly.
    6. Lock object position and change the shader back to normal after the user "places" it.
    7. Do all the fun stuff like transferring client-side placements to the server, checking if the placements are valid, and so forth.
    Should be the gist of it.
     
  3. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Sounds appropriately difficult for a newbie then. We will see I suppose, thanks for the help!
     
  4. subho0406

    subho0406

    Joined:
    Mar 20, 2014
    Posts:
    104