private void Update() { Vector3 a = this.PointToGraphSpace(this.graph.center); Vector3 b = this.PointToGraphSpace(this.target.position); if (AstarMath.SqrMagnitudeXZ(a, b) > this.updateDistance * this.updateDistance) { this.UpdateGraph(); } }
// Update is called once per frame void Update() { // Check the distance along the XZ plane // we only move the graph in the X and Z directions so // checking for if the Y coordinate has changed is // not something we want to do if (AstarMath.SqrMagnitudeXZ(target.position, graph.center) > updateDistance * updateDistance) { UpdateGraph(); } }
/** Update is called once per frame */ void Update() { // Calculate where the graph center and the target position is in graph space var graphCenterInGraphSpace = PointToGraphSpace(graph.center); var targetPositionInGraphSpace = PointToGraphSpace(target.position); // Check the distance in graph space // We only care about the X and Z axes since the Y axis is the "height" coordinate of the nodes (in graph space) // We only care about the plane that the nodes are placed in if (AstarMath.SqrMagnitudeXZ(graphCenterInGraphSpace, targetPositionInGraphSpace) > updateDistance * updateDistance) { UpdateGraph(); } }