Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to ping-pong a train?
#1
Hi I downloaded the asset last night and really love it. I am working on the 12-train demo scene and have made a new track and train which is great!

I want the train to ping-pong at the end of the lines as they won't always be a nice loop, but the rest of the carriages carry on to the end too and all end up overlapping each other... is there any built in way to stop this happening like to treat the whole train as a single object and control that object as a whole, but still maintaining the individual carriages behaviors on the spline in terms of turning nicely etc? If it's possible it'd be nice because then I could just control the speed in a single place too rather than on both axles and the body objects of every single carriage?

So if that made no sense I guess what I'm asking is can I have a parent (or even the loco/engine) object that has the main spline controls on, speed etc, and the carriages still follow it and the spline shape nicely, but stay in order when the engine ping-pongs at the end of a line?
Reply
#2
Try having an OnEndReached event listener for the locomotive where you setup all the other carriages accordingly.
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
(07-10-2020, 11:34 AM)_Aka_ Wrote: Try having an OnEndReached event listener for the locomotive where you setup all the other carriages accordingly.

Thanks I will try this, how can this be set though for the carriages as in how do I force them to think the end is reached when they haven't? Or is it easier to set their direction to reverse or something when the parent reaches the end?

Just trying, but I am unsure how to check if the event has been invoked in code? I cant do it using the interface and dragging the script on to the events part of the curvyspline module. Sorry this is a bit off topic I am quite new the events!

I have declared:

CurvySplineMoveEvent e_EndEvent = new CurvySplineMoveEvent();

then in Start()

e_EndEvent.AddListener(GetComponentInChildren<SplineController>().OnEndReached);

But it's not happy I think because Addlistener is expecting a UnityEvent not a Curvy one? How would I add the listener and then check it has been invoked?

And lastly how would I set the direction of the child objects to Backward? I have read the documentation but I am not sure exactly how this works, I can see there is a .Set method for <SplineController>().MovementDirection but how would I actually set it to Backward?

Sorry if this is too basic for this forum but I appreciate any help to get me going!
Reply
#4
Hi
1- Once the locomotive reached the end, modify the Position and/or MovementDirection and/or other properties of the other controllers to have them do what they are supposed to do.
2- Add a listener like this
OnEndReached.AddListener(Listener);
while having the following method:
void Listener(CurvySplineMoveEventArgs arg0)
{
//your code
}
3- MovementDirection = MovementDirection.Backward;

Don't forget to look at the existing code (using CTRL+SHIFT+F if using visual studio, or the Find all References entry in the right click menu) to see how some specific member is used, it can help you understand how to use it in the future.

Was all this clear?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(07-11-2020, 03:05 PM)_Aka_ Wrote: Hi
1- Once the locomotive reached the end, modify the Position and/or MovementDirection and/or other properties of the other controllers to have them do what they are supposed to do.
2- Add a listener like this
OnEndReached.AddListener(Listener);
while having the following method:
void Listener(CurvySplineMoveEventArgs arg0)
{
  //your code
}
3- MovementDirection = MovementDirection.Backward;

Don't forget to look at the existing code (using CTRL+SHIFT+F if using visual studio, or the Find all References entry in the right click menu) to see how some specific member is used, it can help you understand how to use it in the future.

Was all this clear?

Hi many thanks for this very helpful!
Reply
#6
you are welcome
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
  Train tracks with transparent middle? jh092 4 468 07-03-2020, 07:13 PM
Last Post: _Aka_
  Trying to create a moving train that slows and stops at stations Novian 11 7,570 12-12-2019, 06:40 PM
Last Post: _Aka_
  Train Manger - multiple Trains and Splines teamteam 1 935 11-12-2019, 02:07 PM
Last Post: _Aka_
  Changing train speed richardzzzarnold 1 2,496 06-21-2017, 07:09 PM
Last Post: Jake

Forum Jump: