protected void DebugWorldToGrid() { theGrid.WorldToGrid(_transform.position); if (printLogs) { Debug.Log(theGrid.WorldToGrid(_transform.position)); } }
public static Vector3 WorldToGridFixed(this GFGrid grid, Vector3 worldPosition) { Vector3 fixedPosition = new Vector3(worldPosition.x * 1.25f, worldPosition.y * 0.85f, worldPosition.z); Vector3 gridPosition = grid.WorldToGrid(fixedPosition); return(gridPosition); }
// makes the object snap to the bottom of the grid, respecting the grid's rotation public static Vector3 CalculateOffsetY(GFGrid grid, Transform targetTrans) { //first store the objects position in grid coordinates Vector3 gridPosition = grid.WorldToGrid(targetTrans.position); //then change only the Y coordinate gridPosition.y = 0.5f * targetTrans.lossyScale.y; //convert the result back to world coordinates return(grid.GridToWorld(gridPosition)); }
// makes the object snap to the bottom of the grid, respecting the grid's rotation Vector3 CalculateOffsetY() { //first store the objects position in grid coordinates var gridPosition = _grid.WorldToGrid(transform.position); //then change only the Y coordinate gridPosition.y = 0.5f * transform.lossyScale.y; //convert the result back to world coordinates return(_grid.GridToWorld(gridPosition)); }
public static bool IsAdjacent(this GFGrid theGrid, Vector3 position, Vector3 reference) { //convert to Grid Space first Vector3 gridPosition = theGrid.WorldToGrid(position); //the light we want to test Vector3 gridReference = theGrid.WorldToGrid(reference); //the light that was pressed //pick the implentation based on the type of grid if (theGrid.GetType() == typeof(GFRectGrid)) { return(RectIsAdjacent((GFRectGrid)theGrid, gridPosition, gridReference)); } else if (theGrid.GetType() == typeof(GFHexGrid)) { return(HexIsAdjacent((GFHexGrid)theGrid, gridPosition, gridReference)); } else if (theGrid.GetType() == typeof(GFPolarGrid)) { return(PolarIsAdjacent((GFPolarGrid)theGrid, gridPosition, gridReference)); } else { return(false); } }
// Update is called once per frame void Update() { if (playerCastArea != null && !once && panel != null) { //initPanels(); once = true; } if (Input.GetMouseButtonDown(0)) { Camera cam = player.cam; //(connection.isPlayer1sTurn()) ? player1.cam : player2.cam; Ray r = cam.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(r, 100); foreach (RaycastHit hit in hits) { if (hit.transform.name == "Cube") { Vector3 gPos = grid.WorldToGrid(hit.transform.position); //Debug.Log(gPos); //Debug.Log(inCastableArea(new Vector2(hit.transform.position.x,hit.transform.position.z),playersTurn)); break; } } } }
Vector3 FindNextFace() { //we will be operating in grid space, so convert the position Vector3 newPosition = grid.WorldToGrid(cachedTransform.position); //first let's pick a random number for one of the four possible directions int n = Random.Range(0, 4); //now add one grid unit onto position in the picked direction if (n == 0) { newPosition = newPosition + new Vector3(1, 0, 0); } else if (n == 1) { newPosition = newPosition + new Vector3(-1, 0, 0); } else if (n == 2) { newPosition = newPosition + new Vector3(0, 1, 0); } else if (n == 3) { newPosition = newPosition + new Vector3(0, -1, 0); } //if we would wander off beyond the size of the grid turn the other way around for (int j = 0; j < 2; j++) { if (Mathf.Abs(newPosition[j]) > grid.size[j]) { newPosition[j] -= Mathf.Sign(newPosition[j]) * 2.0f; } } //return the position in world space return(grid.GridToWorld(newPosition)); }