Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to create a moving train that slows and stops at stations
#1
Firstly thank you for such a great and robust asset!

I must admit that I feel a bit daunted attempting to take the great work you have done here and apply it.
My team and I are creating a wild west themed game and we bought Curvy in order to create our train tracks and train system.

I need help doing a few things:

1.) Creating the train tracks (which as I understand it will also be the path).  From the looks of it there is not a way to provide an existing model and have Curvy use that.  Instead you create a Lathe type outline that is then extruded.  I have been picking apart the example scene with the train but this still confuses me.  How can I create a track that is old west themed graphically?  Do I need a new material that is Lathe-able?

2.) I found the controls for the speed of the train and for creating and attaching new train cars but I cannot seem to find a way to create a "speed system".  Obviously we would like the train to start out moving at full speed, then when it approaches a station play the sounds, slow the train and its animations and eventually stop at the station, wait, then start back up again.  Is this sort of thing possible?  How would I go about doing that?

I am happy to research and tinker I just think I need a push in the right direction; get me on the right track you could say Wink

Any and all help is greatly appreciated!

Cheers~
Reply
#2
(08-16-2018, 03:13 PM)Novian Wrote: Firstly thank you for such a great and robust asset!
Thank you.

(08-16-2018, 03:13 PM)Novian Wrote: From the looks of it there is not a way to provide an existing model and have Curvy use that.
This is not the case. If you take a look at scene 12_Train, and search for the game object named Create GO (Sleepers), you can see how this module is used in the Curvy Generator to replicate an existing model along a path.

(08-16-2018, 03:13 PM)Novian Wrote: I have been picking apart the example scene with the train but this still confuses me.
The tracks in the example scenes are made of both an extruded mesh, and objects placed along that mesh. 

(08-16-2018, 03:13 PM)Novian Wrote: How can I create a track that is old west themed graphically?  Do I need a new material that is Lathe-able?
You can use whatever material you want. You can use the Meta CG Options module to precisely control the materials and UV coordinates on each control point of your section. This is done in scene 26_CGExtrusionExtendedUV.

(08-16-2018, 03:13 PM)Novian Wrote: 2.) I found the controls for the speed of the train and for creating and attaching new train cars but I cannot seem to find a way to create a "speed system".  Obviously we would like the train to start out moving at full speed, then when it approaches a station play the sounds, slow the train and its animations and eventually stop at the station, wait, then start back up again.  Is this sort of thing possible?  How would I go about doing that?

The Spline Controller component has two properties that you can use: Speed and Position. So you can either set the position at each frame, or set the speed and let Curvy update the position. Position can be either a relative value (from 0 to 1) or an absolute one (in world units) depending on Position Mode. Same thing with Speed and Move Mode.


Hope this helps. Please keep in mind that for each component, you have an question mark at the top right corner of the inspector that will open a help page about that component.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
@_Aka_ Thanks very much! I will be looking into this more this evening. I appreciate your help. Smile
Reply
#4
Thanks very much for the help, I've made some good progress.  Having a new issue that perhaps you can help me with?  I need to create a train that has 10 cars.  I have 2 so far but when I try to add a third I am having trouble getting the new car to be positioned correctly.  When I first create it (duplicating from the car in front of it) I can set the Position no problem.  After 1 time running the game the position is off (too large of a gap).  So I go to adjust it and now the value is constantly clamping back to the "gap" value.  I am unable to change it.  Any advice?  Thanks!

See attached image for ref.  If I set it to any value other than the 941.269 shown it instantly snaps back to that value.


Attached Files Thumbnail(s)
   
Reply
#5
Hi,
In your message, I distinguish two different issues:
1- The gap appearing between cars: This is something that naturally happens with time due to consecutive operation on floats. There are different ways to try to reduce the issue. One that is already coded can be found in TrainCarManager.LateUpdate(), TrainCarManager being the script used in the scene 12_Train where it manages a train with multiple cars in it. I believe that by following that example, you can fix your issue.
Also, knowing that floats are the most precise between 0 and 1, try using Relative Position Mode and Move Mode, and see if it helps.
2- The impossibility to set a value to the position: I don't have an explanation for this. Are you sure you don't have some code setting the Position value each frame?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
(09-07-2018, 04:24 PM)_Aka_ Wrote: Hi,
In your message, I distinguish two different issues:
1- The gap appearing between cars: This is something that naturally happens with time due to consecutive operation on floats. There are different ways to try to reduce the issue. One that is already coded can be found in TrainCarManager.LateUpdate(), TrainCarManager being the script used in the scene 12_Train where it manages a train with multiple cars in it. I believe that by following that example, you can fix your issue.
Also, knowing that floats are the most precise between 0 and 1, try using Relative Position Mode and Move Mode, and see if it helps.
2- The impossibility to set a value to the position: I don't have an explanation for this. Are you sure you don't have some code setting the Position value each frame?

Thanks very much for the quick response.  1.) I will look into this but each of my "cars' in my train are already using the TrainCarManager script; including TrainCarA (which is the engine).  My obj hierarchy is: Train (with Train Manager Script applied), then its children are TrainCarA-F (each with the TrainCarManager script applied).

2.) I am using no additional scripts that affect the Train at all.  Just base Curvy scripts using the 12_Train scene as an example.

Any insight would be most appreciated!  Thanks!

An additional issue seems to be that only the engine (TrainCarA) is moving from the CP000 to CP0001 and then snapping back to CP0000.  It remains in this infinite loop while the other cars travel along the path correctly (so far, I have to watch them carefully).  Has anyone else had this issue?  See attached image for reference.


Attached Files Thumbnail(s)
   
Reply
#7
I can't think of any explanation for your issues. If you send me a scene/project reproducing the issue I will take a look at it.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
[qoute]Firstly thank you for such a great and robust asset!

I must admit that I feel a bit daunted attempting to take the great work you have done here and apply it.
My team and I are creating a wild west themed game and we bought Curvy in order to create our train tracks and train system.

I need help doing a few things:

1.) Creating the train tracks (which as I understand it will also be the path).  From the looks of it there is not a way to provide an existing model and efforts with phen375 have Curvy use that.  Instead you create a Lathe type outline that is then extruded.  I have been picking apart the example scene with the train but this still confuses me.  How can I create a track that is old west themed graphically?  Do I need a new material that is Lathe-able?

2.) I found the controls for the speed of the train and for creating and attaching new train cars but I cannot seem to find a way to create a "speed system".  Obviously we would like the train to start out moving at full speed, then when it approaches a station play the sounds, slow the train and its animations and eventually stop at the station, wait, then start back up again.  Is this sort of thing possible?  How would I go about doing that?

I am happy to research and tinker I just think I need a push in the right direction; get me on the right track you could say [/quote]
Much obliged in particular! I will investigate this more tonight. I value your assistance. Grin
Reply
#9
Hello there,

I am also trying to animate trains via keyframing but the train won't move.

I am using the standard Unity Animator component on the highest level "Train Object" and keyframe the position value in its Train manager component by recording in the Unity Animation panel. While the value does change, the train just remains stationary.

I have found that it is possible to animate position values in the spline controllers of individual train car parts (wagon/front/rear axis for each car) but then of course the relative spacing between those parts gets lost and all train parts of all cars get the very same position -> a cluster of objects on top of each other moves along the track -.-

Is there another way to animate the position of `just the train´ as a whole?

Best regards,
Bodo
Reply
#10
Hi,
The TrainManager script, which is just an example script, not something that has the quality needed to be on production, has a Position field. This field is used in the setup method to define the position of all the wagons. This happens in two situations:
  • At the script start
  • When values are modified through the inspector
Other than those two situations, the Position field is not used.

When you modify the field's value via the Animator, nothing will happen. If you want it to be used immediately to override the wagons' positions, then the easiest way to do it (and not the most efficient) is to comment the first line of the LateUpdate method. This will make the setup method run every frame. Overkill, yes, but it works.
For the long term, I advise you to use what you learnt from the example scripts to write your own train manager that will suit perfectly your needs.

Did this help?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Heart Create beautiful curves ShiroeYamamoto 3 9 03-26-2024, 06:25 PM
Last Post: _Aka_
  Is it possible to create a road texture at runtime? artsung 1 4 01-30-2024, 09:30 AM
Last Post: _Aka_
Wink Train carriage with 2 bogies following a path arcadeperfect 9 27 08-25-2023, 02:56 PM
Last Post: arcadeperfect
  Moving object down or up the spline using gravity velikizlivuk 6 16 07-26-2023, 10:06 PM
Last Post: _Aka_

Forum Jump: