public void UpdatePath(EntityId id, Path.Update update) { if (Walkers.HasAuthority(id) && Walkers.TryGetValue(id, out var path)) { Connection.SendComponentUpdate(id, update); update.ApplyTo(path); } }
void SetNewPath(EntityId id) { var positions = environment.Positions; if (positions.TryGetValue(id, out var position)) { var startPos = position.Get().Value.coords; var pointA = _navigator.GetNearestPoly(startPos, HalfExtents).Result; if (pointA == null) { Log(LogLevel.Error, "Failed to get point A for [" + id.Id + "] for SetNewPath"); Log(LogLevel.Error, "Point A: " + startPos); Log(LogLevel.Error, pointA.ToString()); return; } var pointB = _navigator.GetRandomPoint().Result; if (pointB == null) { Log(LogLevel.Error, "Failed to get point B for [" + id.Id + "] for SetNewPath"); return; } var smoothPath = _navigator.GetMeshPath(pointA, pointB).Result; if (smoothPath.Status != PathStatus.Success) { Log(LogLevel.Error, "Failed to find smooth path for [" + id.Id + "] for SetNewPath"); return; } var update = new Path.Update { index = 0, path = new Improbable.Collections.List <Vector3d>(), smoothpathlen = smoothPath.Path.Count }; for (int i = 0; i < smoothPath.Path.Count; i += 3) { update.path.Value.Add(smoothPath.Path[i].Target.Coords.ToVector3d()); } environment.UpdatePath(id, update); } else { Log(LogLevel.Error, "Could not find position for [" + id.Id + "] for SetNewPath"); } }