How to make a train stay on the rails?

Hi all,

Firstly, I’m VERY new to Unity. I downloaded the program about 3 weeks ago.

Now, I’d like to create a train simulator game. However due to by basic knowledge, I have no idea how to.

I was wondering if anyone could tell me how I could achieve the following things. or provide the code?:

  • Making it so the train does not
    decelerate on it’s own (just like a
    real one)

  • Making it so it takes a while for the
    train to brake (just like a real one,
    again)

  • Making the train stay on the tracks

  • Making it so if you go too fast, the
    train will derail

  • Realistic sounds

I don’t expect you guys to be able to tell me how to make all of these things happen, but I’d appreciate it if you could at least do the basics like rail-following and the train acceleration system I mentioned before.

Thanks in advance!

@ThePotatoDawg
for making a train stay on the track:
I read that you can use SPLine or WayPoints but I am not clear on them. If you get a solution, Please ping me as well.
does not decelerate:
Make a float variable called speed that needs to be updated by pressing ‘accelerator’(whichever button you assign it to) or brakes. Otherwise it will remain same and you can move your train as per this speed variable.
takes a while for the train to brake:
On hitting ‘Brakes’ your train’s speed variable needs to decrease slowly. Use coroutines for this.
the train will derail:
loose spline and write a script to make it fall sidewards.