public BeamPlace GetPlace(Vector2 pos) { Vector2 gridPos = Ground.NearestGridPoint(pos); int xIdx = (int)Mathf.Floor((gridPos.x - Ground.minX) / Ground.gridSize); // TODO: this is COPY/PASTA EVERYWHERE!!! FIX!!! int zIdx = (int)Mathf.Floor((gridPos.y - Ground.minZ) / Ground.gridSize); //Debug.Log(string.Format("gridPos: {0}, xIdx: {1}, zIdx: {2}", gridPos, xIdx, zIdx)); return(Ground.IndicesAreOnMap(xIdx, zIdx) ? GetPlace(xIdx, zIdx) : null); // note this returns null for "no place" and for "out of bounds" }
public static Vector2 UpcomingGridPoint(Vector2 curPos, Heading curHead) { // it's either the current closest point (if direction to it is the same as heading) // or is the closest point + gridSize*unitOffsetForHeading[curHead] if closest point is behind us Vector2 point = Ground.NearestGridPoint(curPos); if (Vector2.Dot(GameConstants.UnitOffset2ForHeading(curHead), point - curPos) < 0) { point += GameConstants.UnitOffset2ForHeading(curHead) * Ground.gridSize; } return(point); }