Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by AndrewRyan · Jan 31, 2017 at 08:06 PM · controllersplinemodularfollow pathtrain

Train Spline controller?

Hi,

I am making a sort of train simulator but am having trouble perfecting a multi-car train spline controller. I am interested in replicating what I see in this video. Can anyone glean how they might be approaching this controller?


The track system I have in place is modular and prefab-based, unlike in the video, as random path generation is something i'd like to implement in the future. Each of my tracks has it's own spline aligned to the model and the meta-spline path is calculated by a pathfinding algorithm on start() with each track ordered and added to a list to be referenced by trains as they move along the path.

alt text


I currently handle train movement along the path via an iTween implementation where each track has a normalized beginning and end range(0-1) called progress.

     progress += speed / currentTrack.length;

I assign a train's progress via copying the train in front of it's progress and subtract an ideal train distance that has been arc-length parameterized for consistency.

     float GetNormalizedProgress()
     {
         //progress = train in front of me's progress(-)the normalized train-to-train distance
         return GetTrainByIndex(myTrainIndex - 1).progress - 
             train_to_train_Distance/train.currentTrack.length;
     }

When a train reaches 0 or 1 progress, the current spline index is set to the previous or next spline in the list.

 //returns the correct next track
         int GetNextTrack()
         {
             if(progress > 0 && progress < 1) return train.currentTrack;
             if(progress > 1)
             {
                 progress -= 1;
     
                 //if there is a track after this in the array...
                 if(train.currentTrack == 0)
                 {
                     return tm.orderedTracks.Count - 1;
                 }
                 //else, keep going forward
                 else
                 {
                     return train.currentTrack - 1;
                 }
             }
             else if(progress < 0)
             {
                 progress += 1;
     
                 //track has reached the end, set to beginning
                 if(train.currentTrack == tm.orderedTracks.Count - 1)
                 {
                     return 0;
                 }
                 else
                 {
                     return train.currentTrack + 1;
                 }
             }
             return train.currentTrack;
         }

This implementation has worked OK under some circumstances but often produces very glitchy results for heretofore unknown reasons. If anyone has some insight on how, in the video or elsewhere, the train controller could work, or how I might approach it within my described modular system, I would appreciate it greatly.

Thanks!

tracksystem.png (12.5 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Jan 31, 2017 at 08:55 PM 0
Share

you need to collect more data about your glitchiness. when does it happen, what values are used, what values should be used?
what I can say is that you could make the code less error prone using $$anonymous$$athf.Repeat. it wraps values around back and forth

avatar image zero_null · Oct 19, 2018 at 02:04 PM 1
Share

Hello ! Hope you are well. It's been quite a time but did you manage to solve the issue for you? I have been trying to do something similar. For a one cart everything is great but managing multiple carts is something I can't get into work. Please help if you could. I know there are tons of assets on asset store that might help but I just don't wanna use them.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does anyone know a spline system with junctions (for a train simulator)? 1 Answer

How to Make a Train like movement controller 0 Answers

Roll a ball to the direction it is facing 0 Answers

Getting object position along a spline (Surge) 0 Answers

advanced Camera follower 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges