private void MakeRailTo(WaypointNode src, WaypointNode dst, int segmentID) { Vector3 a = src.transform.localPosition; Vector3 b = dst.transform.localPosition; Vector3 dir = (b - a).normalized; a += dir * src.radius; b -= dir * dst.radius; float distance = Vector3.Distance(a, b); waypoints.Add(a); waypoints.Add(b); TrackSection tsp = Instantiate(trackSectionPrefab); tsp.SetEnds(src, dst); tsp.Init(); tsp.transform.SetParent(renderersHolder); tsp.generator = this; tsp.SetPositions(new List <Vector3> { a, b }.ToArray()); }
private void MakeCurveRail(WaypointNode curr, WaypointNode prev, WaypointNode next, int segmentID) { Vector3 a = curr.transform.localPosition + GetDirection(curr.transform, prev.transform) * curr.radius; Vector3 b = curr.transform.localPosition; Vector3 c = curr.transform.localPosition + GetDirection(curr.transform, next.transform) * curr.radius; //float distance = Vector3.Distance(a, b); float distance = (Mathf.PI / 2) * curr.radius; int midpoints = (int)(distance / step); float angleStep = step / (curr.radius * (Mathf.PI / 2)); List <Vector3> points = new List <Vector3>(); TrackSection tsp = Instantiate(trackSectionPrefab); tsp.SetEnds(prev, next); tsp.Init(); for (int i = 0; i < midpoints; i++) { Vector3 x = Vector3.Lerp(a, b, i * angleStep); Vector3 y = Vector3.Lerp(b, c, i * angleStep); points.Add(Vector3.Lerp(x, y, i * angleStep)); } tsp.transform.SetParent(curr.transform); tsp.generator = this; tsp.SetPositions(points.ToArray()); }