Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to face forwards when going backwards
#1
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
Reply
#2
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.
Reply
#3
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)
Reply
#4
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
Reply
#5
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.
Reply
#6
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?
Chip
Deko Games
dekogames.com
Reply
#7
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.
Reply
#8
Thanks once again for the quick reply! I'll create a demo to try to explain what I mean.
Chip
Deko Games
dekogames.com
Reply
#9
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.
Chip
Deko Games
dekogames.com
Reply
#10
No worries
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to make the face at the end of mesh? Chanon 3 6 11-14-2024, 04:38 PM
Last Post: _Aka_
  issues with face over lapping and generator ranges Mos Def 7 2,317 12-13-2020, 07:46 AM
Last Post: _Aka_
  Make GameObject Face towards Spline Path linkinballzpokemon 5 2,394 07-14-2020, 08:27 PM
Last Post: _Aka_
  UI Text move backwards/reverse along Spline Cloov 4 8,351 12-18-2016, 11:56 AM
Last Post: Jake

Forum Jump: