0
\$\begingroup\$

I want to make a train that can move in a curve. I have downloaded a Train Spline Walker unity package. That package can generate a spline, and the train's locomotive will move in the spline with a flexible direction and rotation. It'll start by the 1st point of the Bézier spline and stop at the last point. I read the code and I'm pretty sure that those points are called ControlPoints.

The problem is that I want the train to also be able to move in a line. Because you know, trains in reality can move in a line and also along curves.

The rails (including 2 types: Rail type A is a straight line and rail type B is a curve) can be auto-generated to fit geometrical rules.

I want to attach the Bézier spline to a rail type B (curve) so that each time the locomotive collides with the collision point (which is an empty object I make) of the type B rails, it will follow a script and move along that Bezier spline.

Through a comment suggestion, i have changed the straight line into curve 0 degree, now im trying to change the locomotive from moving a spline into the next spline.

But it didn't work.

Can anyone suggest how to change the locomotive status from moving in a spline to moving in the next spline when it meets the next rail?

This is the link to the code i downloaded: https://onlinegdb.com/gjpF5Snjq

\$\endgroup\$
8
  • 2
    \$\begingroup\$ With only that much information, you won't get a good answer. We don't know which spline train asset you use, how it works or what you did so far. The question should contain a minimal working scene or at least the code that is relevant \$\endgroup\$
    – Zibelas
    Commented Sep 6, 2023 at 10:38
  • \$\begingroup\$ A straight line is just a cubic Bézier curve with its middle two control points placed ⅓ and ⅔ of the way along the line between the start/end anchor points. So you could implement both straight line rail segments and curved segments with Béziers, using the same code for all rail following, if switching between two rail behaviours is what's giving you trouble. \$\endgroup\$
    – DMGregory
    Commented Sep 6, 2023 at 12:36
  • \$\begingroup\$ My gratitude to you first, i have thought about implementing both of them as Bezier, the problem is, when the locomotive moves in the spline of straight rail has travel to the end point of the spline, i want it to move to the next spline. \$\endgroup\$ Commented Sep 7, 2023 at 1:32
  • \$\begingroup\$ I don't know how to do that, really sorry for making confusions. \$\endgroup\$ Commented Sep 7, 2023 at 1:32
  • \$\begingroup\$ onlinegdb.com/gjpF5Snjq \$\endgroup\$ Commented Sep 7, 2023 at 1:49

0

You must log in to answer this question.

Browse other questions tagged .