Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Railroad game quick start.

Discussion in 'Scripting' started by username132323232, Jun 29, 2015.

  1. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    473
    Hi. I would like to create a railroad-based game, but I have a very vague idea of how to "build" a railroad and make the train follow the rails. I spent a couple of hours in the Asset Store, but didn't find a working example. There are several car-racing projects, but I suspect that moving a train along the railroad will be somewhat different.

    Can somebody give me an idea where to start? Some example code would be great. Thanks!
     
  2. psyydack

    psyydack

    Joined:
    Aug 30, 2013
    Posts:
    93
    Hi!

    Well, we built a game based in railroad and exist too many ways to work around. I'll tell you 2 of I tested:

    1- Raycast
    You create a "main trail" and put your car above with one (or more) raycast to down and rotate according to normals. Apply some force to forward.

    2- Follow Line
    This way is nothing special, its more fast to prototype but you have some limitations. You create a spline and put your car to follow. You cant change directions rotations, etc. But, you can divert this limitations.


    =)
     
    username132323232 likes this.
  3. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    There are some Spline assets in the store which will help you create your paths and move objects along them, some are better than others at various things, one of them does even have a helper script for moving train objects along a spline.
     
    username132323232 likes this.
  4. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    473
    Thanks everyone for the suggestions! I wonder if there's any significant difference between a train following a railway and a car automatically following a road. I think the tricky part is making all the wheels stay exactly on the rail.