public override void Move(GridLayout grid, GameObject layer, BoundsInt from, BoundsInt to) { for (int i = 0; i < selection.Count; ++i) { selection[i].transform.Translate(grid.CellToWorld(to.min) - grid.CellToWorld(from.min)); } }
private void SelectWalkable(Tilemap tilemap) { Vector3Int gridMousePosition = GridMousePosition(); Vector3 cellPosition = grid.CellToWorld(gridMousePosition) + new Vector3(0, .5f, 0); selectionOutline.transform.position = cellPosition; if (Input.GetMouseButtonDown(0)) { List <Vector3Int> availableDestinationTiles = player.AvailableDestinationTiles(tilemap); if (availableDestinationTiles.Contains(gridMousePosition)) { Debug.Log("AvailableDestinationTiles contains GridMousePosition!"); BoundsInt cellBounds = tilemap.cellBounds; Vector2Int navGridDestination = GameManager.instance.TileIndexOnNavGrid(cellBounds, gridMousePosition); player.Move(navGridDestination, tilemap.CellToWorld(gridMousePosition) + new Vector3(0, .25f, 0)); //cellPosition? } else { Debug.Log("AvailableDestinationTiles does NOT contain GridMousePosition!"); } } }
void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); clickCellPosition = gridLayout.WorldToCell(ray.origin); clickDistance = Vector3.Distance(gridLayout.CellToWorld(clickCellPosition), gridLayout.CellToWorld(movementController.playerCellPosition)); //Debug.Log("Click distance: " + clickDistance); Debug.Log("Click position: " + clickCellPosition); //Debug.Log(Vector3.Distance(gridLayout.CellToWorld(clickCellPosition), gridLayout.CellToWorld(movementController.playerCellPosition))); if (clickDistance < 0.35f) { //Debug.Log("Pre Player Transform: "+playerTransform.position); playerTransform.position += (gridLayout.CellToWorld(clickCellPosition) - gridLayout.CellToWorld(movementController.playerCellPosition)); //Debug.Log("Post Player Transform: " + playerTransform.position); //Debug.Log("Delta Click Cell Position: " + (gridLayout.CellToWorld(clickCellPosition) - gridLayout.CellToWorld(movementController.playerCellPosition))); movementController.playerCellPosition = gridLayout.WorldToCell(playerTransform.position); playerTransform.position = gridLayout.CellToWorld(movementController.playerCellPosition); //Debug.Log("Adj Player Transform: " + playerTransform.position); mapManager.UpdateFogOfWar(movementController.Vision, movementController.playerCellPosition); //Debug.Log("Player Cell Position: " + gridLayout.CellToWorld(movementController.playerCellPosition)); } } }
public static void DrawQuadBatched(GridLayout grid, Vector3Int position) { GL.Vertex(grid.CellToWorld(position)); GL.Vertex(grid.CellToWorld(position + Vector3Int.up)); GL.Vertex(grid.CellToWorld(position + Vector3Int.up + Vector3Int.right)); GL.Vertex(grid.CellToWorld(position + Vector3Int.right)); }
public override void Move(GridLayout grid, GameObject layer, BoundsInt from, BoundsInt to) { Tilemap map = GetTilemap(); List <TileBase> tiles = new List <TileBase>(); foreach (var pos in from.allPositionsWithin) { tiles.Add(map.GetTile(pos)); map.SetTile(pos, null); } int index = 0; foreach (var pos in to.allPositionsWithin) { map.SetTile(pos, tiles[index++]); } Vector3 worldFrom = grid.CellToWorld(from.min); Vector3 worldTo = grid.CellToWorld(to.min); foreach (var turret in m_Selected) { turret.transform.Translate(worldTo - worldFrom); } }
private void SpawnThings() { BoundsInt bounds = groundMap.cellBounds; int enemyCount = 0; int enemyShotGunCount = 0; int chestCount = 0; while (enemyCount < enemyCountToSpawn) { Vector3Int pos = new Vector3Int(Random.Range(bounds.xMin, bounds.xMax), Random.Range(bounds.yMin, bounds.yMax), 0); TileBase tile = groundMap.GetTile(pos); Vector3 where = gridLayout.CellToWorld(pos); if (tile == groundTile) { if (Vector3.Distance(player.transform.position, where) > 2) { GameObject enemyI = Instantiate(enemy, where, Quaternion.identity); enemyCount++; } } } while (chestCount < chestCountToSpawn) { Vector3Int pos = new Vector3Int(Random.Range(bounds.xMin, bounds.xMax), Random.Range(bounds.yMin, bounds.yMax), 0); TileBase tile = groundMap.GetTile(pos); Vector3 where = gridLayout.CellToWorld(pos); if (tile == groundTile) { if (Vector3.Distance(player.transform.position, where) > 2) { Instantiate(chest, where, Quaternion.identity); chestCount++; } } } while (enemyShotGunCount < enemyShotGunCountToSpawn) { Vector3Int pos = new Vector3Int(Random.Range(bounds.xMin, bounds.xMax), Random.Range(bounds.yMin, bounds.yMax), 0); TileBase tile = groundMap.GetTile(pos); Vector3 where = gridLayout.CellToWorld(pos); if (tile == groundTile) { if (Vector3.Distance(player.transform.position, where) > 2) { Instantiate(enemyShotGun, where, Quaternion.identity); enemyShotGunCount++; } } } }
} //! findPath public bool findActivableTarget(WireChunk iChunk) { Vector3Int up = iChunk.coord + new Vector3Int(0, 1, 0); Vector3Int down = iChunk.coord + new Vector3Int(0, -1, 0); Vector3Int left = iChunk.coord + new Vector3Int(-1, 0, 0); Vector3Int right = iChunk.coord + new Vector3Int(1, 0, 0); // switch to woorld coordinate Vector3 worldcoord_up = GL.CellToWorld(up); Vector3 worldcoord_down = GL.CellToWorld(down); Vector3 worldcoord_left = GL.CellToWorld(left); Vector3 worldcoord_right = GL.CellToWorld(right); // ALT solution : Make a cache with activable objects pos and compare distance with woorldcoord_x // check if there is an activable object in current radius Vector2 up_center = new Vector2(worldcoord_up.x, worldcoord_up.y); Vector2 down_center = new Vector2(worldcoord_down.x, worldcoord_down.y); Vector2 left_center = new Vector2(worldcoord_left.x, worldcoord_left.y); Vector2 right_center = new Vector2(worldcoord_right.x, worldcoord_right.y); float radius = 1.0f; ContactFilter2D filter = new ContactFilter2D(); filter.NoFilter(); List <Collider2D> up_col = new List <Collider2D>(5), down_col = new List <Collider2D>(5), left_col = new List <Collider2D>(5), right_col = new List <Collider2D>(5); int res_up = Physics2D.OverlapCircle(up_center, radius, filter, up_col); int res_down = Physics2D.OverlapCircle(down_center, radius, filter, down_col); int res_left = Physics2D.OverlapCircle(left_center, radius, filter, left_col); int res_right = Physics2D.OverlapCircle(right_center, radius, filter, right_col); if (res_up > 0) { iChunk.AddTargets(LookForActivables(up_col)); } if (res_down > 0) { iChunk.AddTargets(LookForActivables(down_col)); } if (res_left > 0) { iChunk.AddTargets(LookForActivables(left_col)); } if (res_right > 0) { iChunk.AddTargets(LookForActivables(right_col)); } return(iChunk.targets.Count > 0); }
public override void Move(GridLayout grid, GameObject layer, BoundsInt from, BoundsInt to) { Vector3 fromWorld = grid.CellToWorld(from.min); Vector3 toWorld = grid.CellToWorld(to.min); Vector3 move = toWorld - fromWorld; foreach (var turret in m_Selection) { turret.transform.Translate(move); } }
void PopulateCloud() { GameObject cloudParent = new GameObject("Clouds"); var bottomBound = gridLayout.CellToWorld(bottomLeftCell); var topBound = gridLayout.CellToWorld(topRightCell); var centre = (bottomBound + topBound) / 2; var dist = (topBound - bottomBound) / 2; for (int i = 0; i < 10; i++) { clouds.Add(Instantiate(cloudPrefab, new Vector3(Random.Range(-dist.x, dist.x), Random.Range(-dist.y, dist.y), 0) + centre, Quaternion.identity, cloudParent.transform)); } }
public bool CheckLine(Vector3Int startPos_w, Vector3Int endPos_w, int maxdist = 20, bool checkentities = false) { Vector3 offset = new Vector3(0.5f, 0.5f, 0); Vector3 startPos = grid.CellToWorld(startPos_w) + offset; Vector3 endPos = grid.CellToWorld(endPos_w) + offset; startPos[2] = 0; endPos[2] = 0; if ((startPos - endPos).magnitude > maxdist) { return(true); } Debug.Log("started:" + startPos); Debug.Log("ended:" + endPos); RaycastHit2D hit2D = Physics2D.Linecast(startPos, endPos, LayerMask.GetMask("Walls")); if (hit2D) { return(true); } return(false); /*Vector3Int offset = new Vector3Int(xmin, ymin, 0); * Vector3Int startPos = startPos_w - offset; * startPos[2] = 0; * * Vector3Int endPos = endPos_w - offset; * endPos[2] = 0; * Vector3 checkPos = startPos_w - offset; * Vector3 step = (new Vector3(endPos.x - startPos.x, * endPos.y - startPos.y, * 0)).normalized; * if ((startPos - endPos).magnitude > maxdist) { return true; } * int i, j; * int breaker = 0; * while (Vector3Int.FloorToInt(checkPos) != endPos && breaker < maxdist) * { * breaker++; * checkPos += step; * i = Mathf.RoundToInt(checkPos.x); * j = Mathf.RoundToInt(checkPos.y); * Debug.Log(checkPos+offset + " " + passable[i, j]); * if (i == startPos.x && j == startPos.y) { continue; } * if (!passable[i, j]) { return true; } * if (checkentities && HasObj(i + xmin, j + ymin)) { return true; } * } * return false;*/ }
public override void OnPaintSceneGUI(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing) { lastBoundsInt = position; //base.OnPaintSceneGUI(gridLayout, brushTarget, position, tool, executing); //Handles.Label(gridLayout.CellToWorld(position.position), position.position.ToString()); var zPosition = new Vector3Int(position.min.x, position.min.y, position.min.z); BoundsInt newPosition = new BoundsInt(zPosition, position.size); Vector3 offset = new Vector3(0f, 0f, -0.1f); Vector3[] cellLocals = new Vector3[] { gridLayout.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.min.y, newPosition.min.z)) + offset, gridLayout.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.min.y, newPosition.min.z)) + offset, gridLayout.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.max.y, newPosition.min.z)) + offset, gridLayout.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.max.y, newPosition.min.z)) + offset }; Handles.color = Color.blue; int index = 0; for (int j = cellLocals.Length - 1; index < cellLocals.Length; j = index++) { Handles.DrawLine(cellLocals[j], cellLocals[index]); } var labelText = "Pos: " + new Vector3Int(position.x, position.y, position.z); if (position.size.x > 1 || position.size.y > 1) { labelText += " Size: " + new Vector2Int(position.size.x, position.size.y); } Handles.Label(gridLayout.CellToWorld(new Vector3Int(position.x, position.y, position.z)) + offset, labelText); }
Vector3Int cellPosition; //Create a variable to store the cellPosition of the object void Awake() { //Awake should run before anything else in the game gridLayout = GameObject.Find("Grid").GetComponent <GridLayout>(); //Get and store reference to the grid object cellPosition = gridLayout.WorldToCell(transform.position); //Get the position of this object and convert it to the coordinates of the nearest hex transform.position = gridLayout.CellToWorld(cellPosition); //Take the coordinates of the nearest cell, convert them back to world coordinates and assign that position to this object. }
void Start() { GridLayout gridLayout = transform.parent.GetComponentInParent <GridLayout>(); Vector3Int cellPosition = gridLayout.WorldToCell(transform.position); transform.position = gridLayout.CellToWorld(cellPosition); }
// Update is called once per frame void Update() { Vector3 world = new Vector3(transform.position.x, 0, transform.position.z); Vector3Int iso = grid.WorldToCell(world); transform.position = grid.CellToWorld(iso); }
public IEnumerator firePipe(int manaUsed, Spells s) { s.showSpell(0, 5); //change 1 to the animation Destroy(s.GetComponent <CircleCollider2D>()); BoxCollider2D bc = s.gameObject.AddComponent <BoxCollider2D>(); bc.offset = new Vector2(0, 0); bc.size = new Vector2(1, 1.2f); bc.isTrigger = true; Vector3 mouse = Input.mousePosition; mouse = Camera.main.ScreenToWorldPoint(mouse); GridLayout gl = floorCreator.main.transform.parent.GetComponent <GridLayout>(); Vector3Int cellCoords = gl.WorldToCell(mouse); Vector3 finalPos = gl.CellToWorld(cellCoords) + new Vector3(0.5f, 0.5f, 0); s.gameObject.transform.parent.position = finalPos; yield return(new WaitForSeconds(0.2f)); s.onEnter = fireEnter; for (int i = 0; i < 5; i++) { hitList(s.inside, manaUsed / 1.5f, "fire"); yield return(new WaitForSeconds(1f)); } destroySpell(s); }
public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing) { base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing); if (coordinateBrush.z != 0) { var zPosition = new Vector3Int(position.min.x, position.min.y, coordinateBrush.z); var newPosition = new BoundsInt(zPosition, position.size); var cellLocals = new[] { grid.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.min.y, newPosition.min.z)), grid.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.min.y, newPosition.min.z)), grid.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.max.y, newPosition.min.z)), grid.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.max.y, newPosition.min.z)) }; Handles.color = Color.blue; var i = 0; for (var j = cellLocals.Length - 1; i < cellLocals.Length; j = i++) { Handles.DrawLine(cellLocals[j], cellLocals[i]); } } Handles.Label(grid.CellToWorld(new Vector3Int(position.x, position.y, coordinateBrush.z)), new Vector3Int(position.x, position.y, coordinateBrush.z).ToString()); }
public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing) { base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing); if (position.z != 0) { var zPosition = new Vector3Int(position.min.x, position.min.y, position.min.z); BoundsInt newPosition = new BoundsInt(zPosition, position.size); Vector3[] cellLocals = new Vector3[] { grid.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.min.y, newPosition.min.z)), grid.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.min.y, newPosition.min.z)), grid.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.max.y, newPosition.min.z)), grid.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.max.y, newPosition.min.z)) }; Handles.color = Color.blue; int i = 0; for (int j = cellLocals.Length - 1; i < cellLocals.Length; j = i++) { Handles.DrawLine(cellLocals[j], cellLocals[i]); } } var labelText = "Pos: " + new Vector3Int(position.x, position.y, position.z); if (position.size.x > 1 || position.size.y > 1) { labelText += " Size: " + new Vector2Int(position.size.x, position.size.y); } Handles.Label(grid.CellToWorld(new Vector3Int(position.x, position.y, position.z)), labelText); }
public static Vector3 GetMapWorldCenter(Vector2 mapSize, Vector3Int cellPos, GridLayout gridLayout) { Vector3 vector3 = gridLayout.CellToWorld(cellPos); vector3.y = vector3.y + mapSize.y * 0.5f; return(vector3); }
// Update is called once per frame void Update() { transform.position = gridLayout.CellToWorld(player_location); if (Input.GetKeyDown(KeyCode.A)) { if (cooldown == false) { move.y -= 1; ti.tick = true; t.go(); Invoke("ResetCooldown", 0.25f); cooldown = true; } } if (Input.GetKeyDown(KeyCode.D)) { if (cooldown == false) { move.y += 1; ti.tick = true; t.go(); Invoke("ResetCooldown", 0.25f); cooldown = true; } } if (Input.GetKeyDown(KeyCode.W)) { if (cooldown == false) { move.x += 1; ti.tick = true; t.go(); Invoke("ResetCooldown", 0.25f); cooldown = true; } } if (Input.GetKeyDown(KeyCode.S)) { if (cooldown == false) { move.x -= 1; ti.tick = true; t.go(); Invoke("ResetCooldown", 0.25f); cooldown = true; } } /// Debug.Log(System.Array.IndexOf(nonwalkable_tiles, obstacles.GetTile(player_location)) == -1); if (System.Array.IndexOf(nonwalkable_tiles, obstacles.GetTile(player_location + move)) == -1) { player_location += move; player_tilemap.ClearAllTiles(); player_tilemap.SetTile(player_location, player_tile); } move = Vector3Int.zero; }
public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position) { Vector2 halfCellSize = grid.cellSize / 2; GameObject go = Instantiate(BlockPrefab, (Vector2)grid.CellToWorld(position) + halfCellSize, Quaternion.identity); go.transform.parent = grid.transform; }
public Vector3 mapV3ToWorldPos(Vector2Int pos) { Vector3 WorldPos = gridLayout.CellToWorld(new Vector3Int(pos.x, pos.y, 0)); WorldPos.x += 0.5f; WorldPos.y += 0.5f; return(WorldPos); }
//public string script = "otherRoom"; //public System.Type script_type = System.Type.GetType(script + ",Assembly-CSharp"); // Use this for initialization void Start() { GridLayout gridLayout = transform.parent.GetComponentInParent <GridLayout>(); Vector3Int cellPosition = gridLayout.WorldToCell(transform.position); transform.position = gridLayout.CellToWorld(cellPosition); self_extent = (Vector3)transform.GetComponent <TilemapRenderer>().bounds.extents; }
// Update is called once per frame void Update() { if (canMove) { if (Input.GetButtonDown("Click")) { a = Input.mousePosition; destPosition = Camera.main.ScreenToWorldPoint(a); print(destPosition.x); print(destPosition.y); print(a.x); print(a.y); } tempPosition = Vector2.MoveTowards(tempPosition, destPosition, step); // convert continous to discrete, if same cell then no movement Vector3Int cellPosition = gridLayout.WorldToCell(tempPosition); if (transform.position != gridLayout.CellToWorld(cellPosition)) { if (GetComponent <Collider2D>().IsTouchingLayers(LayerMask.GetMask("highLand"))) { if ((availablePoint - 2) >= 0) { availablePoint -= 2; transform.position = gridLayout.CellToWorld(cellPosition); } } else { // normal place transform.position = gridLayout.CellToWorld(cellPosition); availablePoint--; } tempPosition = transform.position; updateAPtext(); } if (availablePoint == 0) { endTurn(); } } }
void Start() { startingDir = direction; _playerLocation = spawnLocation; Vector3 cellPosition = grid.CellToWorld(_playerLocation); cellPosition.y += grid.cellSize.y / 2f; player = Instantiate(boat, cellPosition, Quaternion.identity); particle = player.transform.GetChild(0).GetChild(4).gameObject; playerAnim = player.transform.GetChild(0).GetComponent <Animator>(); north = player.transform.GetChild(0).GetChild(0).gameObject; south = player.transform.GetChild(0).GetChild(1).gameObject; west = player.transform.GetChild(0).GetChild(2).gameObject; east = player.transform.GetChild(0).GetChild(3).gameObject; changeDir(); cellPosition = grid.CellToWorld(endLocation); cellPosition.y += grid.cellSize.y / 2f; finish = Instantiate(end, cellPosition, Quaternion.identity); for (int i = 0; i < trashLocations.Count; i++) { cellPosition = grid.CellToWorld(trashLocations[i]); cellPosition.y += grid.cellSize.y / 2f; trashList.Add(Instantiate(trash, cellPosition, Quaternion.identity)); } trashTotal = trashLocations.Count; }
public override void OnPaintSceneGUI(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing) { BoundsInt gizmoRect = position; bool refreshPreviews = false; if (Event.current.type == EventType.Layout) { int newPreviewRefreshHash = GetHash(gridLayout, brushTarget, position, tool, m_GridTileBrush); refreshPreviews = newPreviewRefreshHash != m_LastPreviewRefreshHash; if (refreshPreviews) m_LastPreviewRefreshHash = newPreviewRefreshHash; } // Move preview - To be fully implemented on the next version /* if (tool == GridBrushBase.Tool.Move) { if (refreshPreviews && executing) { ClearPreview(); PaintPreview(gridLayout, brushTarget, position.min); } } // Paint preview else*/ if (tool == GridBrushBase.Tool.Paint || tool == GridBrushBase.Tool.Erase) { if (refreshPreviews) { ClearPreviewAll(); if (tool != GridBrushBase.Tool.Erase) { PaintPreview(gridLayout, brushTarget, position.min); } } gizmoRect = new BoundsInt(position.min - m_GridTileBrush.pivot, m_GridTileBrush.size); } // BoxFill Preview else if (tool == GridBrushBase.Tool.Box) { if (refreshPreviews) { ClearPreviewAll(); BoxFillPreview(gridLayout, brushTarget, position); } } base.OnPaintSceneGUI(gridLayout, brushTarget, gizmoRect, tool, executing); // Paint the hovered grid position onto the scene var labelText = "Grid Position: " + position.position; if (position.size.x > 1 || position.size.y > 1) { labelText += " Size: " + position.size; } GUIStyle style = new GUIStyle(); style.normal.textColor = Color.black; Handles.Label(gridLayout.CellToWorld(position.position), labelText, style); }
public Vector2 CalculateBuildPosition(int cellIndex) { int maxX = constructableGrid[cellIndex].Select(g1 => g1.x).Max(); int maxY = constructableGrid[cellIndex].Select(g2 => g2.y).Max(); Vector3Int currentCellPosition = constructableGrid[cellIndex].SingleOrDefault(g => g.x == maxX && g.y == maxY); return(gridLayout.CellToWorld(new Vector3Int(currentCellPosition.x + BUILDING_POSITION_OFFSET, currentCellPosition.y + BUILDING_POSITION_OFFSET, 0))); }
public static Vector2 NormalizedPosition(Vector2 worldPosition) { if (GridLayout != null) { var cellPos = GridLayout.WorldToCell(worldPosition); return(GridLayout.CellToWorld(cellPos) + new Vector3(0, CellSize.y / 2)); } return(new Vector2()); }
//public void GetMovementDirection() //{ // //The GetMovementDirection function determines the players intended movement based on updown and left right keys // if (upDownMovement < 0) // { // if (sidewaysMovement > 0) // { // direction = new Vector3(0.5f, -0.5f); //Move player down right // } // else if (sidewaysMovement < 0) // { // direction = new Vector3(-0.5f, -0.5f); //Move player down left // } // else // { // direction = new Vector3(0, -1, 0); //Move player down // } // // } // else if (upDownMovement > 0) // { // if (sidewaysMovement > 0) // { // direction = new Vector3(0.5f, 0.5f); //Move player up right // } // else if (sidewaysMovement < 0) // { // direction = new Vector3(-0.5f, 0.5f); //Move player up left // } // else // { // direction = new Vector3(0, 1, 0); //Move player up // } // } // //Once direction is determined, the player transform is moved to that location and centered in the destination cell // // transform.position += direction * moveScale; // playerCellPosition = gridLayout.WorldToCell(transform.position); // transform.position = gridLayout.CellToWorld(playerCellPosition); // mapManager.UpdateFogOfWar(vision, playerCellPosition); //A call to the fog of war function is made to update what the player can see //} public void MovePlayer(Vector3Int moveTarget, bool regularMove) { SetOrientation(gridLayout.CellToWorld(moveTarget)); //first, orient the ship correctly for the hex it will be moving to transform.position += (gridLayout.CellToWorld(moveTarget) - gridLayout.CellToWorld(playerCellPosition)); //update the player game object transform position to the new coordinates from the clicked cell (look at how to do this smoothly) playerCellPosition = gridLayout.WorldToCell(transform.position); //update the player cell position //transform.position = gridLayout.CellToWorld(playerCellPosition); //use the updated player cell position to ensure the player game object is centered in the cell playerCellPositionCubeCoords = mapManager.evenq2cube(playerCellPosition); //transform.position = Vector3.Lerp(transform.position,gridLayout.CellToWorld(playerCellPosition),Time.deltaTime); //use the updated player cell position to ensure the player game object is centered in the cell mapManager.UpdateFogOfWar(vision, playerCellPosition); //clear the fog of was from the new position if (regularMove) { hasMoved = true; if (turnManager.combatActive && abilityController.AbilityUsed) { uiController.SetEndTurnButtonState(); } } //Debug.Log("has moved is "+hasMoved); }
void Awake() { //Awake should run before anything else in the game gridLayout = GameObject.Find("Grid").GetComponent <GridLayout>(); //Get and store reference to the grid object mapManager = GameObject.Find("GameController").GetComponent <ManageMap>(); cellPosition = gridLayout.WorldToCell(transform.position); //Get the position of this object and convert it to the coordinates of the nearest hex transform.position = gridLayout.CellToWorld(cellPosition); //Take the coordinates of the nearest cell, convert them back to world coordinates and assign that position to this object. planetMinedIcon = transform.GetChild(0).gameObject; planetMinedIcon.SetActive(false); }
// Start is called before the first frame update void Start() { // snaps object to the grid GridLayout gridLayout = transform.parent.GetComponentInParent <GridLayout>(); Vector3Int cellPosition = gridLayout.WorldToCell(transform.position); transform.position = gridLayout.CellToWorld(cellPosition); Tracker.Units.Add(gameObject); }