private void onPathComplete(Vector3 start, Vector3 destination, List <GridPoint> points, bool showMarker) { List <Vector3> path = new List <Vector3>(); if (points != null) { // Remove first and last grid points as they will be replaced by the exact start and end positions if (points.Count >= 2) { points.Remove(points.First()); points.Remove(points.Last()); } path.Add(start); path.AddRange(points.Select(o => TownGenerator.instance.GridPointToWorldPos(o.x, o.y) + new Vector3(0.5f, 0, 0.5f))); path.Add(destination); } // Smooth and clean path path = Pathfinder.SmoothPath(path); Pathfinder.RemoveRedundantNodes(path); searchingForPath = false; createPath(path, showMarker); }
private void createPath(List <Vector3> nodes, bool showMarker) { if (nodes.Count < 1) { return; } // nodes.AddRange(additionalPathNodes); // additionalPathNodes.Clear(); path = new CharacterMovementPath(nodes, accCurve, decCurve, delegate(Vector3 node) { lookDir = node - transform.position; }, delegate { currentSpeed = 0; hasReachedDestination = true; path = null; }); path.SetTargetNode(1); if (showMarker) { Instantiate(moveMarkerPrefab, nodes.Last(), Quaternion.identity); } }
public void MoveToPoint(Vector3 target, bool run = false, bool showMarker = false, bool usePathFinding = true) { isRunning = run; path = null; hasReachedDestination = false; // additionalPathNodes.Clear(); if (usePathFinding) { // Start finding path asynchronously, call SetPath when complete findPathAsync(TownGenerator.instance.GridPoints, transform.position, target, showMarker); } else { // Set a path on a straight line between current position and target createPath(new List <Vector3>() { transform.position, target }, showMarker); } }