Posts: 29
Threads: 14
Joined: May 2020
Hi there,
My train engine faces forwards when going forwards, but if I change the direction it flips around and faces "forwards" when going backwards. I don't want this behaviour, rather, I would like the train to be "reversing" when going backwards (so still facing the other direction).
The trouble is my connected splines are not necessarily facing the same direction, so setting IgnoreDirection doesn't work because then the train just flip-flops between directions as it changes splines.
I hope this makes sense, maybe I'm missing something obvious but thanks for your help.
John
Posts: 2,111
Threads: 92
Joined: Jun 2017
Hi,
If having splines with inverted directions is not necessary, you can change one of your splines' direction by using the Flip tool in the toolbar on your second spline https://curvyeditor.com/documentation/toolbar#spline_actions
Otherwise, you will have to use a custom connection handler (see here https://curvyeditor.com/documentation/controllers#connections_handling, then Custom). And in that connection handler, set the controller's MovementDirection as you see fit.
Did this help?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 29
Threads: 14
Joined: May 2020
Ah, flipping the splines was the key as I don't care which way they face. Now they are flipped I don't need to worry about forwards/backwards issue.
Thank you
(Finally left a review too, thanks for all your time so far)
Posts: 29
Threads: 14
Joined: May 2020
Sorry, one more thing. I thought I had it working but not quite. How do I know which way a spline is facing? I need to know whether to flip a spline or not, I had this code but turns out it's not right:
Code:
bool IsSplineForwards(CurvySpline spline)
{
return spline.GetTangent(0.5f).z > 0;
}
thanks
John
Posts: 2,111
Threads: 92
Joined: Jun 2017
The way I would have done it (warning, pseudo code, might not compile due to minor mistakes):
Vector3 closestPointSecondSpline;
secondSpline.GetNearestPointTF(firstSpline.Interpolate (1f, Space.Word), out closestPointSecondSpline), Space.Local);
float closestPointOnSecondSplineTF = secondSpline.GetNearestPointTF(closestPointSecondSpline, Space.Local);
Vector3 tangentOne = firstSpline.GetTangent(1f, Space.World);
Vector3 tangentTwo = secondSpline.GetTangent(closestPointOnSecondSplineTF, Space.World);
Now you have tangents of both closest point on the splines. Compare their direction by using a Dot Product, and that's it.
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 11
Threads: 4
Joined: Jan 2019
08-26-2020, 10:44 PM
(This post was last modified: 08-26-2020, 10:45 PM by DekoGames.)
I have a similar issue -- I thought there might be a simple solution already but it doesn't appear to be so. I'd like to create a loop back track from a switch (where the follow up spline from the main branch loops back to the diverging branch (in railroad terms, a 'balloon track'). Reading the solution above, I can get it to work by flipping the follow up spline, but I'd rather not do that -- I think it's going to get messy if there are multiple trains on the track -- and would much rather be able to set the spline controller logic to deal with it by using a connecting point listener and attaching a script at the CP. But so far, all in my attempts to do a double reverse -- changing the various parameters of the spline controller (trying ignore direction, flip flop, etc.) -- the train just gets stuck, flip-flopping at the connection point. Do you have any suggestions?
Posts: 2,111
Threads: 92
Joined: Jun 2017
Hi,
The spline flipping is done once in edit mode, so I don't see how having multiple trains should create an issue. Can you please explain that?
If you can provide me with a simple scene reproducing your setup, I will try to find a solution tomorrow (it's midnight over here) as soon as I finish releasing the next update (it's nearly ready)
Have a nice day
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 11
Threads: 4
Joined: Jan 2019
Thanks once again for the quick reply! I'll create a demo to try to explain what I mean.
Posts: 11
Threads: 4
Joined: Jan 2019
Sorry, I see now that it looks like an issue with my code -- using a stripped down model with just the Spline Controller class produces the desired results with no flip-flopping.
Posts: 2,111
Threads: 92
Joined: Jun 2017
No worries
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.