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

Coding a train?

Discussion in 'Scripting' started by sgemmen9, Oct 29, 2015.

  1. sgemmen9

    sgemmen9

    Joined:
    Jul 24, 2015
    Posts:
    17
    Hi,

    Does anyone have some basic scripts they might be willing to share for making a train move? I have assets for the train, a few passenger cars, and the tracks. I'm looking to push a button to move forward, and another to move backward. I hear that turning is the hardest part. I looked into pathfinding/waypoints for turning but at this point I'm still learning unity and coding so I should slow down and start with forward and backward motion first.

    Please help, thanks!
     
    Kameron-Schwab likes this.
  2. Puganaught

    Puganaught

    Joined:
    Jun 27, 2013
    Posts:
    1
    Hey,

    fellow beginner here, what you could do if the train has a simple path is use a collider on an invisible quad and when the train hits it, it could turn 10 or 20 degrees or so.

    Hope this helps get the brain going :)
     
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    I would say that any script that moves anything around would work. Modifying the transform is all you need to do.
     
    sgemmen9 likes this.
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I saw someone recommend getting the train & carriages to follow a spline that was the rail track.
     
    sgemmen9 likes this.
  5. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    There is a Spline system on the asset store that has a component in it just for moving multiple objects along paths and the example that can be seen in the video below is a toy train with multiple carriages all with independent wheels moving along a track that is also generated by the asset.
     
  6. flonch

    flonch

    Joined:
    Aug 20, 2014
    Posts:
    63
    sgemmen9 likes this.
  7. Kameron-Schwab

    Kameron-Schwab

    Joined:
    Sep 16, 2015
    Posts:
    33
    That cost about $90-150