private void Update() { if (pointIndex == -1) { return; } // Start point OnlineMapsVector2d p1 = points[pointIndex]; // End point OnlineMapsVector2d p2 = points[pointIndex + 1]; // Total step distance double dx, dy; OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, p2.x, p2.y, out dx, out dy); double stepDistance = Math.Sqrt(dx * dx + dy * dy); // Total step time double totalTime = stepDistance / speed * 3600; // Current step progress progress += Time.deltaTime / totalTime; OnlineMapsVector2d position; if (progress < 1) { position = OnlineMapsVector2d.Lerp(p1, p2, progress); marker.SetPosition(position.x, position.y); // Orient marker if (orientMarkerOnNextPoint) { marker.rotation = 1.25f - OnlineMapsUtils.Angle2D((Vector2)p1, (Vector2)p2) / 360f; } } else { position = p2; marker.SetPosition(position.x, position.y); pointIndex++; progress = 0; if (pointIndex >= points.Length - 1) { Debug.Log("Finish"); pointIndex = -1; } else { // Orient marker if (orientMarkerOnNextPoint) { marker.rotation = 1.25f - OnlineMapsUtils.Angle2D(p2, points[pointIndex + 1]) / 360; } } } if (lookToMarker) { OnlineMaps.instance.SetPosition(position.x, position.y); } OnlineMaps.instance.Redraw(); }
private void Update() { if (pointIndex == -1) { return; } // Start point OnlineMapsVector2d p1 = points[pointIndex]; // End point OnlineMapsVector2d p2 = points[pointIndex + 1]; double p1x, p1y, p2x, p2y; map.projection.CoordinatesToTile(p1.x, p1.y, map.zoom, out p1x, out p1y); map.projection.CoordinatesToTile(p2.x, p2.y, map.zoom, out p2x, out p2y); // Total step distance double dx, dy; OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, p2.x, p2.y, out dx, out dy); double stepDistance = Math.Sqrt(dx * dx + dy * dy); // Total step time double totalTime = stepDistance / speed * 3600; // Current step progress progress += Time.deltaTime / totalTime; OnlineMapsVector2d position; if (progress < 1) { position = OnlineMapsVector2d.Lerp(p1, p2, progress); marker.SetPosition(position.x, position.y); // Orient marker targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90; } else { position = p2; marker.SetPosition(position.x, position.y); pointIndex++; progress = 0; if (pointIndex >= points.Length - 1) { Debug.Log("Finish"); pointIndex = -1; } else { OnlineMapsVector2d p3 = points[pointIndex + 1]; map.projection.CoordinatesToTile(p2.x, p2.y, map.zoom, out p1x, out p1y); map.projection.CoordinatesToTile(p3.x, p3.y, map.zoom, out p2x, out p2y); targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90; } } marker.rotationY = Mathf.LerpAngle(marker.rotationY, targetRotation, Time.deltaTime * 10); marker.GetPosition(out lng, out lat); map.SetPosition(lng, lat); }