Posts: 8
Threads: 3
Joined: Aug 2023
08-23-2023, 04:47 AM
Hi
For a train simulation, I'd like the carriages to follow a spline path.
Train carriages generally have two bogies upon which the carriage pivots, which are a fixed distance from one another.
However if the train is not on straight track the arc length between the bogies on the curve will be variable, so simply traversing the curve twice with an offset won't work
I can't find any trivial solutions to this problem. Any suggestions welcome!
Posts: 2,114
Threads: 92
Joined: Jun 2017
Hi
The black arc is called Arc Length, and the green line is called Cord Length.
The relationship between these two values is probably defined mathematically for all the spline types supported by Curvy Splines. I personally never looked at this subject. As an example here is an example of this relationship for a simple circle:
https://www.omnicalculator.com/math/arc-length
The rigourous way would be to to compute the arc length based on the cord length and the used spline type, then set the second bogie's position as: first bogie position + arc length
The easy way to do, that I would recommend for most cases, is to first set the bogie's position as if the arc length is equal to the desired cord length, and the compute the actual cord length. If it varies too much from the desired cord length, then increase/decrease the bogie's position a bit an then repeat until you get close enough to the desired cord length.
I hope this helped.
Have a nice day
I never looked for the relationship between these two for all the types of splines supported by Curvy Splines. Probably such relationship exists,
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 22
Threads: 5
Joined: Jul 2023
08-23-2023, 10:41 AM
(This post was last modified: 08-23-2023, 10:43 AM by velikizlivuk.)
Once both are connected just move first one while second Absolut position if first one plus some distance? If moving along spline direction +distance if against then -distance or vice versa not sure about that. You can make distance random in range or depending on speed to achieve more realistic train like movement. Do this in Update or FixedUpdate depending on movement type (transform or rigidbody).
Posts: 8
Threads: 3
Joined: Aug 2023
08-23-2023, 02:16 PM
(This post was last modified: 08-23-2023, 02:25 PM by arcadeperfect.)
Another thought I had - I'm already subdividing the spline to draw it with a polyline from another library. I could just drive the first bogie, check the straight line segments from the subdivision for intersections with a circle of radius equal to the cord length, and use that position.
Or even just generate straight line segments from the points cache and check those.
Posts: 22
Threads: 5
Joined: Jul 2023
08-24-2023, 10:40 AM
(This post was last modified: 08-25-2023, 09:18 PM by velikizlivuk.)
Isn't difference of Absolute positions of two objects on spline equal to distance between those two?
Or use Relative position combined with spline length? Do not use Relative position look at few posts bellow.
Posts: 8
Threads: 3
Joined: Aug 2023
(08-24-2023, 10:40 AM)velikizlivuk Wrote: Isn't difference of Absolute positions of two objects on spline equal to distance between those two?
Or use Relative position combined with spline length?
The problem is that in this case you need to calculate the arc length from the chord length in order to know where on the spline in terms of TF the bogeys will fall, which isn't a simple thing to calculate for a spline.
Posts: 2,114
Threads: 92
Joined: Jun 2017
That difference is equal to the arc length* between the two. Do not use the Relative position for that use. If you wonder why, check this video: https://www.youtube.com/watch?v=rP0zuAEoVJw&list=PLatR0iPtXq-xxul-Ys-vQSLMaLXQnaU65&index=4
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 2,114
Threads: 92
Joined: Jun 2017
08-25-2023, 10:55 AM
(This post was last modified: 08-25-2023, 11:02 AM by _Aka_.)
(08-24-2023, 05:28 PM)arcadeperfect Wrote: "That difference is equal to the arc length between the two" is false. The chord length does not always equal the arc length.
By "That difference" I mean the different between "Absolute positions" as stated in the question.
Absolute Position is a float typed property of the controller. It defines the arc distance between a point and the spline's start.
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 2,114
Threads: 92
Joined: Jun 2017
(08-24-2023, 05:28 PM)arcadeperfect Wrote: This is why _AKA_ suggested an iterative approach whereby I increase the arc length and check the resulting chord length, until it is within some tolerance. I'll probably go with that.
If you end up choosing another way, it would be much appreciated if you let us know.
Don't hesitate to ask questions if needed.
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: 8
Threads: 3
Joined: Aug 2023
Please disregard my previous post, I got confused