diff --git a/impulse/Assets/Scripts/Road/RoadGenerator.cs b/impulse/Assets/Scripts/Road/RoadGenerator.cs index 902be7d6f8390b2a954e80d7b49430fef9560c04..fb6cbc3f6733354eca98319723b31bbb7382f47b 100644 --- a/impulse/Assets/Scripts/Road/RoadGenerator.cs +++ b/impulse/Assets/Scripts/Road/RoadGenerator.cs @@ -35,9 +35,10 @@ public class RoadGenerator : MonoBehaviour void Start() { - //int seed = (int)System.DateTime.Now.Ticks; - //Debug.Log("Seed custom utilisé : " + seed); - Random.InitState(-1324498718); + int seed = (int)System.DateTime.Now.Ticks; + //seed = 1728374951; + Debug.Log("SEED : " + seed); + Random.InitState(seed); ApplyPlayerPrefs(this.roadPartBlueprintList); // Fix iterations @@ -150,6 +151,21 @@ public class RoadGenerator : MonoBehaviour placedRoads.Add(nextRoadPart); } } + + // Ensures that if the very last road part (end) collided with any road part, to fix it and re-inject it. + GameObject lastPiece = gameObject.transform.childCount > 0 ? gameObject.transform.GetChild(gameObject.transform.childCount - 1).gameObject : null; + if (lastPiece == null || !lastPiece.name.StartsWith(roadPartEnd.gameObject.name)) + { + Debug.LogWarning("Missing End road part. Forcing End placement."); + GameObject previousRoad = gameObject.transform.GetChild(gameObject.transform.childCount - 1).gameObject; + GameObject forcedEnd = SpawnRoadPart(roadPartEnd); + ConnectRoadParts(previousRoad, forcedEnd); + placedRoads.Add(forcedEnd); + } + + // Allows to filter ALL destroyed road part. + placedRoads = placedRoads.Where(r => r != null).ToList(); + LogManager.Instance.RegisterParcourLength(CalculateTotalDistanceFromStartEnd()); } @@ -251,6 +267,7 @@ public class RoadGenerator : MonoBehaviour } badRoadPart = newRoadPart; + placedRoads.RemoveAll(r => r == null || r.name == badRoadPart.name); // If every road part bluepint are still colliding, take one step back and try again if (i == 1 && IsColliding(badRoadPart))