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 ?
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.
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 ?
You could do that, or give the track object a script that will help with logic. Code (csharp): public enum Direction { North=1, East=2, South=4, West=8, Up=16, Down=32 } // bit fields public List<Direction> neighbors = new List<Direction>(); // when placing a new track, populate the neighbors public Direction GetTravelDirection(Direction comingIn) { Direction goingOut = Direction.North; // decide which way to send the cart based on where it came from TODO return goingOut; } 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.
If the track make a S shape and I want the cart to be push in velocity(Physic) and stay on the track ?