Creating a curved train track in game

Greetings,

I am currently working on a train track creator tool for my game, and I’m looking for the best approach to achieve this. I would like the player to be able to select point 1 (indicated by the red brick) and point 2 (indicated by the blue brick) with their mouse (the points may not be snapped to a grid). I need a way to create a slight curve between the two points and then fill it with train tracks that are 1-12 studs long.

The tracks I need to fill the curve between the points will look like this:

Furthermore, I would like the same system to work for other angles, such as those shown in these images:

- obrazek - obrazek

However, I also need to prevent the creation of way too insane curves, that a real train couldn’t use, such as this one:
obrazek

I have considered using a linear curve, but I am unsure how to implement it with the rail fill (where the rails rotate so they “fit” correctly).

Thank you for any help.

I don’t have the exact solution for you, but I would highly recommend that you take a look at Bézier curve. I have never experimented with them before, but from what I understand, you should be able to make a curved path and check if any angles are too strong for a train to pass on it.

2 Likes

Thank you, I will try some experimenting with Bézier Curves, I will mark your reply as a solution and if I have more questions I will simply reply again. Thanks.

I would highly suggest that you use them as follows:
image

P0: Starting point
P3: Ending point
P1: A point that is right in front of P0 and that has half of the distance from it as P0 and P3 have,
P2: Same thing, a point that is as far as half of the distance between start and end AND that is in front of P3.

Here is another image to explain my saying:


Therefor, you get proportionate angles from wherever the starting and finish points are and whatever their angle is.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.