Search Unity

How to create player build able paths in game.

Discussion in 'Getting Started' started by AcidicPaper, Jan 25, 2016.

  1. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    Hello Everyone.

    My name is Dean. I am relatively new to Unity and C# programming, whilst I may be relatively new to this whole new world I have plenty of ambition to spend in it.

    Screen Shot 2016-01-25 at 14.39.14.png
    Presently, this is what the "general" idea of my game will hopefully look like once it reaches play mode. I want to be able to know how to build paths as the player (so the path blocks are reserved in the UI for player selection, much like The Sims or RollerCoaster Tycoon) and drag said pathways to the player's desire. Walls will be separate and can be cleared too for player further expansion. The chess pieces in the game are the game's "people". They will follow the path to a designated destination = hereby rewarding the player with progress in the game.

    My biggest obstacle I am presently facing is knowing how to implement this build feature for the paths. If I can clear this, I am certain it will be a monumental victory for my progress and self esteem, and will arm me the courage to continue developing this game which has sort of become my second identity now.

    EDIT: I should also point out the graphic in the bottom left corner (with the arrow piece in the centre) is the constructor tag that will visually guide the player in showing where the next block of path will go.

    So, Unity Community, if anyone knows of the knowledge I seek - How to build paths as the player when in-game - please feel free to enlighten me, or if there are appropriate Unity tutorials that I should check, as so far I have been unable to yield any results.

    Sincere thanks to all of you, Ladies and Gentlemen.

    Dean
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, it looks like you've selected a grid-based world, which is certainly a good idea if you're fairly new to this. What you're trying to do is pretty big magic to begin with, and it would be quite a bit harder still if you didn't stick to a grid.

    But since you are using a grid, you can simply instantiate a prefab wherever the user clicks the mouse. (Use Mathf.Round to round the position clicked to the nearest row and column of your grid; to keep the math simple, define 1 unit in the world to be 1 grid cell.)

    Of course this isn't the most efficient way to do it; if your worlds are going to be large, you will probably eventually switch to procedural mesh generation. But as a beginner, I think you shouldn't worry about that for a while (if ever).
     
  3. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    I'm familiar with the Math.Round, it's covered in the Udemy tutorial I'm taking for Block Breaker, if you're familiar with that?

    Regardless, using Math.Round will ensure what I desire can happen? :)
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    That's part of it, in combination with the other things I pointed out, yes.