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 /
avatar image
0
Question by GrKl · Aug 18, 2017 at 06:15 AM · navmeshpathfindingwaypoint systemtrain

Train Track pathfinding - Navmesh? Waypoints? Spline?

Hi all,

I'm here to ask you what solution you think would be best for train tracks & pathfinding & train movements on the tracks.

What I'm trying to do:

  • Allow user to place their own tracks. No need to have free-form tracks, could be built with a series of pre-built tracks pieces (curves, straight, stations,...)

  • Separate tracks in 'blocks' using signals

  • Have trains pick the best path using pathfinding

  • Of course, move the trains when needed along those path/trains in a relatively realistic manner

  • Trains should be able to have constant/smooth speed/acceleration and follow the tracks/curves smoothly

  • End game should allow tens (hundreds?) of trains moving constantly. So the solution should be light enough to run on non-NASA computers... Target is PC, not phone nore tablets

The different solutions I have thought of:

  • Physics. Seems like to worse idea. Tracks & train wheels should have colliders. Seems like the worse even if tweeks could maybe make this possible. Would be the worse for CPU even if working

  • Splines. Seems too complicated for my application, I do not need free form train track laying

  • Waypoints. Seems like the easiest solutions, each track piece could have pre-placed waypoints, all separated by the same distance. Already did early testing, seems ok for now. Exactly the same spacing between all waypoints allows to have smooth movement and constant speed. Waypoints at intersections could be use for a 'simple' path finding algorithm

  • NavMesh. This one has been proposed to me by a friend, telling me that in recent version of Unity, one could bake them at runtime. If working, might be the lightest solution. I have doubts about width issues on the tracks. Also have doubts on how to later use signals on my tracks to separate tracks in 'blocks'

Main dilemma I have for now is weather to continue on a waypoint system, or to switch to NavMeshes & bake them each time a new track has been added/removed (this would happen frequently)

Any thoughts? Thanks for your time

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by hexagonius · Aug 18, 2017 at 08:52 AM

  • Physics: very bad idea, indeed

  • Splines: Have no idea of their length, so no predictable speeds along paths

  • Waypoints: seems tedious to place all those manually

  • NavMesh: Used for area navigation, unsuitable for straight, predictable tracks.

As I see it, since you're not going for freeform tracks, you must have some sort of grid, any kind of predefined pattern to place the tracks on. If that's so, you know all the distances you need. What I would do is imlpementing an A* algorithm to sort out which the best path is and does so very fast. You could create a large array of gridInfoPieces. Each piece knows which direction it is connected, if it's passable, if it's on a slope, whatever you need. With every track piece added or removed, you change that array structure. A* should be able to run through that grid and get you the paths you need.
Smooth movement along curves would just be calculating radian measure, sin, cos, you name it. The grid and tracks and trains moving might be very visible on screen, but that distracts from the underlying logic they simply are. Data consisting of distance, path, connectivity etc..

Comment
Add comment · Show 4 · Share
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 GrKl · Aug 21, 2017 at 11:31 AM 1
Share

Thanks for your feedback.

Actually, pathfinding is not really the issue I admit. I should of been more clear.

$$anonymous$$ain point was on the different implementation solution. I actually now think splines would be the best solution. Even if this was not an original goal, allowing free-form tracks would of course be much cooler than pre-built small track pieces. I am trying to implement them currently, early test show that I should have listen more in math class when I was young... But it is clearly doable. You cant indeed find the 100% exact length of a spline, but you actually can get pretty close by cheating a bit. I don't need the 0.0001% precision in any case

For the pathfinding, not sure what I'll use exactly, but it wont have to be very complicated. I think a grid in this case would actually be slower than using nodes. Since tracks can only change direction at intersections, there wont be a lot of possible routes for each path requested. So I'll just need to store the junctions locations, the distance between each of them and the directions they can take (if not both) from one junction to the next. Then use any pathfinding algorithm that will allow me to find the shortest path

Thanks again!

avatar image christoph_r GrKl · Aug 21, 2017 at 12:35 PM 0
Share

You can also utilise A* on a node network.

avatar image DarshanP · Aug 21, 2017 at 11:54 AM 0
Share

isn't navmesh pathfinding in unity implement a* algorithm?

avatar image hexagonius DarshanP · Aug 22, 2017 at 05:54 AM 0
Share

Yes, but it's area based which is easy too much for his purposes.

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

74 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

Related Questions

check if an object is reachable 2 Answers

Is it possible to translate a NavMesh at runtime? 2 Answers

Why isn't a Ai Waypoint Spawning??? 0 Answers

walking through the countryside ? 1 Answer

Navmesh with destructible obstacles 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