Skip to content

Commit 25261e8

Browse files
committed
correct issue identifying car behind when cars uncoupled
1 parent 721d843 commit 25261e8

File tree

1 file changed

+6
-3
lines changed
  • Source/Orts.Simulation/Simulation/Physics

1 file changed

+6
-3
lines changed

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5591,19 +5591,22 @@ public void UpdateCouplerSlack(float elapsedTime)
55915591
car.DistanceM += Math.Abs(car.SpeedMpS * elapsedTime);
55925592

55935593
// Identify links to cars ahead and behind for use when animating couplers
5594-
if (j == 0)
5594+
if (j == 0) // typically the locomotive
55955595
{
55965596
car.CarAhead = null;
55975597
if (Cars.Count > j) // if not a single loco
55985598
{
5599-
car.CarBehind = Cars[j + 1];
5599+
if (j != Cars.Count - 1) // if so, this is the last car, and hence no cars behind it
5600+
{
5601+
car.CarBehind = Cars[j + 1];
5602+
}
56005603
}
56015604
else // if a single loco
56025605
{
56035606
car.CarBehind = null;
56045607
}
56055608
}
5606-
else if (j == Cars.Count - 1)
5609+
else if (j == Cars.Count - 1) // last car in train
56075610
{
56085611
Cars[j].CarAhead = Cars[j - 1];
56095612
Cars[j].CarBehind = null;

0 commit comments

Comments
 (0)