Search Unity

Minecraft mining Rail system

Discussion in 'Scripting' started by Poinball, Jun 25, 2019.

  1. Poinball

    Poinball

    Joined:
    Feb 23, 2016
    Posts:
    42
    Hey guys, I want to make a system where we can build Rail on the ground and a Mining Cart would follow the track Like Minecraft for example.

    How should I do it ?
     
  2. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    What do you already have developed? If you have a building system already, then placing a track object and a cart object should be handled through that, then the cart can check which direction it can go on the track under it.
     
  3. Poinball

    Poinball

    Joined:
    Feb 23, 2016
    Posts:
    42
    Yes, The building system is already there.

    How the Cart know in witch direction to go ? I make a Raycast that hit the tracks and look at the orientation of it ?
     
  4. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    You could do that, or give the track object a script that will help with logic.
    Code (csharp):
    1. public enum Direction { North=1, East=2, South=4, West=8, Up=16, Down=32 } // bit fields
    2.  
    3. public List<Direction> neighbors = new List<Direction>(); // when placing a new track, populate the neighbors
    4.  
    5. public Direction GetTravelDirection(Direction comingIn)
    6. {
    7.     Direction goingOut = Direction.North;
    8.     // decide which way to send the cart based on where it came from TODO
    9.     return goingOut;
    10. }
    A rough idea, would need some other supporting code to convert the direction to a vector for the cart. The orientation might be easier if you don't need the tracks to do anything else, though.
     
  5. Poinball

    Poinball

    Joined:
    Feb 23, 2016
    Posts:
    42
    If the track make a S shape and I want the cart to be push in velocity(Physic) and stay on the track :p ?