protected Vector3Int GetNextTargetCellTowardsGoal(Vector3Int goalCellPos) { var candidateCellTargets = GetCandidateCellTargets(); if (candidateCellTargets.Count > 1) { Vector3Int closestCandidate = Vector3Int.zero; float shortestDistance = float.PositiveInfinity; foreach (var candidate in candidateCellTargets) { var dist = Vector3Int.Distance(candidate, goalCellPos); if (dist < shortestDistance) { closestCandidate = candidate; shortestDistance = dist; } } return(closestCandidate); } else if (candidateCellTargets.Count == 1) { return(candidateCellTargets[0]); } return(currentCellPos); }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { SceneManager.LoadScene(0); } if (!_follow) { return; } PlayerController player = GameManager.Instance.Player; if (Mathf.Abs(Input.GetAxis("Horizontal")) > float.Epsilon || Mathf.Abs(Input.GetAxis("Vertical")) > float.Epsilon) { _freeMov = true; FreeMove(); } if (Vector3Int.Distance(_currentPos, player.Position) < 1 || _freeMov) { return; } CenterOn(player.Position); _currentPos = player.Position; }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { var creature = animator.GetComponent <CreatureBehavior>(); if (creature != null) { if (creature.StateTime > 5f) { creature.StateTime = 0; animator.SetBool("IsChasing", false); creature.SetTarget(null); return; } var game = GameManager.current; var target = Vector3Int.FloorToInt(game.player.transform.position); var position = Vector3Int.FloorToInt(creature.transform.position); if (Vector3Int.Distance(target, position) < 10f) { creature.SetTarget(target); } else { creature.SetTarget(null); } } }
public void EditTerrain(Vector3 pointHit, float radius, float newDensityVal) { Vector3Int chunkPos = new Vector3Int((int)(pointHit.x / chunkSize) * chunkSize, (int)(pointHit.y / chunkSize) * chunkSize, (int)(pointHit.z / chunkSize) * chunkSize); int rad = Mathf.FloorToInt(radius); Vector3Int pointHitInt = new Vector3Int(Mathf.CeilToInt(pointHit.x), Mathf.CeilToInt(pointHit.y), Mathf.CeilToInt(pointHit.z)); for (int x = -rad; x <= rad; x++) { for (int y = -rad; y <= rad; y++) { for (int z = -rad; z <= rad; z++) { if (chunkDict.TryGetValue(chunkPos, out Chunk chunk)) { Vector3Int worldCoord = pointHitInt; worldCoord = worldCoord - new Vector3Int(chunkPos.x + x, chunkPos.y + y, chunkPos.z + z); int index = indexFromCoord(worldCoord.x, worldCoord.y, worldCoord.z, numPointsPerAxis); if (newDensityVal > 0) { chunkDict[chunkPos].densityArray[index] = Vector3Int.Distance(worldCoord, pointHitInt); } else { chunkDict[chunkPos].densityArray[index] = -Vector3Int.Distance(worldCoord, pointHitInt); } } } } } UpdateChunk(chunkPos); }
static HashSet <Vector3Int> OpenCells(Tilemap map, Vector3Int start, Vector3Int goal) { Dictionary <Vector3Int, int> counts = new Dictionary <Vector3Int, int>(); counts.Add(goal, 0); HashSet <Vector3Int> openCells = new HashSet <Vector3Int>(); float minDist = Mathf.Infinity; int minCount = int.MaxValue; map.BreadthFirstTraversal(goal, Utils.FourDirections, (current, next) => { float dist = Vector3Int.Distance(goal, next); int count = counts[current] + 1; counts[next] = count; if ((map.IsCellEmpty(next) || next == start) && dist <= minDist) { minDist = dist; minCount = count; openCells.Add(next); } return(count <= minCount && map.IsInBounds(next)); }); return(openCells); }
private void OnMouseMove(Vector2 location) { lastMousePosition = location; if (gridManager == null || frozen) { return; } mouseGridLocation = gridManager.Grid.WorldToCell(location); if (Vector3Int.Distance(mouseGridLocation, characterGridLocation) <= selectionTileDistance) { selectionGameObject.gameObject.SetActive(displaySelectionView); if (gridManager != null) { selectionGameObject.transform.position = (Vector2)gridManager.Grid.CellToWorld(mouseGridLocation) + gridOffset; currentSelectionGridPosition = mouseGridLocation; } } else { selectionGameObject.gameObject.SetActive(false); currentSelectionGridPosition = characterForwardGridLocation; } }
private void DirectClosestStationIndicator() { if (Map.Stations.Count == 0) { ClosestStationIndicator.SetActive(false); } else { Vector3Int?closest = null; float minDist = 0; Vector3Int playerPosition = Player.Position + Map.TopLeft; foreach (Vector3Int station in Map.Stations) { float tmpDist = Vector3Int.Distance(playerPosition, station); if (closest != null && !(tmpDist < minDist)) { continue; } closest = station; minDist = tmpDist; } if (closest == null) { return; } float angle = Mathf.Atan2(closest.Value.x - playerPosition.x, playerPosition.y - closest.Value.y); angle = angle * Mathf.Rad2Deg; ClosestStationIndicator.transform.eulerAngles = new Vector3(0, 0, angle + ClosestStationIndicatorOffset); } StationsLeftText.text = Map.Stations.Count.ToString(); }
//Pick all the tiles far enough from the starting poisiton (taken to be the (0,0) tile) and place random tiles there void generateBombs() { List <Vector3Int> goodTiles = new List <Vector3Int>(); foreach (var position in floorTilemap.cellBounds.allPositionsWithin) { if (!floorTilemap.HasTile(position)) { continue; } if (Mathf.CeilToInt(Vector3Int.Distance(position, spawnPoint)) < minBombDistance) { continue; } goodTiles.Add(position); } Debug.Log("The number of viable tiles for the bomb is: " + goodTiles.Count); for (int i = 0; i < numberOfBombs; i++) { Vector3Int chosenPosition = goodTiles[Random.Range(0, goodTiles.Count)]; //Checking if a bomb has been placed here already if (myTilemap.HasTile(chosenPosition)) { i--; continue; } myTilemap.SetTile(chosenPosition, bombTile); dropBomb(chosenPosition); } }
private static void AddObstacles(Node[] gridNodes, NodeWalkable playerStartNode, float density, ObstaclePattern pattern, int minPlayerStartClearance) { for (int i = 0; i < gridNodes.Length; ++i) { NodeWalkable walkableNode = gridNodes[i] as NodeWalkable; if (walkableNode != null && walkableNode != playerStartNode) { // Don't add obstacles on edges of the cube. if (walkableNode.UpVectors != null && walkableNode.UpVectors.Length == 1) { if (Random.value <= density) { float nodeDistanceToPlayer = Vector3Int.Distance(playerStartNode.Coordinates, walkableNode.Coordinates); if (nodeDistanceToPlayer > minPlayerStartClearance) { if (CheckIfNodeMatchesObstaclePattern(walkableNode, pattern) == true) { walkableNode.SetAsObstacle(); } } } } } } }
private MNode CompareThisLocation <T>(Vector3Int location, Dictionary <Vector3Int, T> nodes) where T : MNode { MNode closestNode = null; float shortestDistance = -1f; foreach (KeyValuePair <Vector3Int, T> node in nodes) { float _distance = Vector3Int.Distance(location, node.Key); if (shortestDistance < 0) { shortestDistance = _distance; closestNode = node.Value; } else if (_distance > shortestDistance) { continue; } else if (_distance == 0) { continue; } else if (_distance < shortestDistance) { shortestDistance = _distance; closestNode = node.Value; } } return(closestNode); }
internal override WorldTile GetDestinationTile(Vector3Int currentPosition, List <WorldTile> cellsInMoveRadius, List <Vector3Int> deniedDestinations) { var player = Spawner.Player; var playerPos = new Vector3Int(Mathf.FloorToInt(player.transform.position.x), Mathf.FloorToInt(player.transform.position.y), 0); //We want to move farther away from the player position WorldTile playerTile; if (GameTiles.tiles.TryGetValue(playerPos, out playerTile)) { var availableSquares = cellsInMoveRadius.Where(p => !deniedDestinations.Any(p2 => p2 == p.LocalPlace)).ToList(); WorldTile currentDestination = null; float shortestDistanceFromPlayer = Vector3Int.Distance(playerTile.LocalPlace, currentPosition); foreach (var availableDestination in availableSquares) { var distanceToPlayer = Vector3Int.Distance(playerTile.LocalPlace, availableDestination.LocalPlace); if (distanceToPlayer < shortestDistanceFromPlayer) { currentDestination = availableDestination; shortestDistanceFromPlayer = distanceToPlayer; } } return(currentDestination); } else { Console.WriteLine("Could not get the player tile"); } return(null); }
public override void CalculateDensity() { base.CalculateDensity(); for (int x = 0; x <= worldWidth; x++) { for (int y = 0; y <= worldHeight; y++) { for (int z = 0; z <= worldLength; z++) { Vector3Int current = new Vector3Int(x, y, z); float distance = Vector3Int.Distance(current, position); float _density = distance - radius; if (_density > 1 || _density < -1) { _density = Mathf.Clamp(_density, -1, 1); } else { if (polygon > 0 && polygon < 1) { _density = ((int)(_density / polygon)) * polygon; } } density[x, y, z] = _density; } } } }
private int[,,] GetSphereMatrix() { int sphereDiameter = SphereRadius * 2; int[,,] matrix = new int[sphereDiameter + 2, sphereDiameter + 2, sphereDiameter + 2]; Vector3Int sphereCenter = new Vector3Int(SphereRadius, SphereRadius, SphereRadius) + Vector3Int.one; for (int i = 1; i < sphereDiameter; i++) { for (int j = 1; j < sphereDiameter; j++) { for (int k = 1; k < sphereDiameter; k++) { Vector3Int currentCoordinate = new Vector3Int(i, j, k); float distanceToCenter = Vector3Int.Distance(currentCoordinate, sphereCenter); if (distanceToCenter <= SphereRadius) { matrix[i, j, k] = 1; } } } } return(matrix); }
/// <summary> /// <para>Draw a cylinder between p1 & p2</para> /// <para>Mode: 0 - overlay, 1 - add, 2 - inverse</para> /// </summary> static public void Cylinder(SurfaceMap surfaceMap, Vector3Int p1, Vector3Int p2, int radius, int material) { if (p1.x < 0 || p1.x >= surfaceMap.resolution || p1.y < 0 || p1.y >= surfaceMap.resolution || p1.z < 0 || p1.z >= surfaceMap.resolution) { throw new Exception("p1OutOfBounds"); } if (p2.x < 0 || p2.x >= surfaceMap.resolution || p2.y < 0 || p2.y >= surfaceMap.resolution || p2.z < 0 || p2.z >= surfaceMap.resolution) { throw new Exception("p2OutOfBounds"); } float distance = Vector3Int.Distance(p1, p2); Quaternion rotation = Quaternion.FromToRotation(new Vector3Int(1, 0, 0), p2 - p1); for (int x = 0; x < distance; x++) { for (int z = -radius; z <= radius; z++) { for (int y = -radius; y <= radius; y++) { if (Mathf.Pow(y, 2) + Mathf.Pow(z, 2) <= radius * radius) { //dodać mody Vector3Int pointOnCylinder = Vector3Int.RoundToInt(rotation * new Vector3(x, y, z)); surfaceMap.SetMaterial(p1.x + pointOnCylinder.x, p1.y + pointOnCylinder.y, p1.z + pointOnCylinder.z, material); surfaceMap.SetMaterial(p1.x + pointOnCylinder.x + 1, p1.y + pointOnCylinder.y + 1, p1.z + pointOnCylinder.z + 1, material); } } } } }
/// <summary> /// Generates new chunks around player. /// </summary> private static void GenerateNewChunks() { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); List <Chunk> chunksToGenerate = new List <Chunk>(); foreach (KeyValuePair <Vector2Int, Column> column in columns) { foreach (Chunk chunk in column.Value.Chunks) { if (Vector3Int.Distance(chunk.ChunkPos, playerCurrentChunkPos) <= GameManager.Instance.StartingColumnRadius + 1 && chunk.HasGeneratedChunkData == true && chunk.HasGeneratedMeshData == false && chunk.HasGeneratedGameObject == false) { chunksToGenerate.Add(chunk); } } } foreach (Chunk chunk in chunksToGenerate) { chunk.GenerateMeshData(); AddActionToMainThreadQueue(chunk.GenerateChunkGameObject); } stopwatch.Stop(); long elapsedMS = stopwatch.ElapsedMilliseconds; if (chunksToGenerate.Count > 0) { Logger.Log($@"* GENERATE: Took {elapsedMS.ToString("N", CultureInfo.InvariantCulture)} ms to generate {chunksToGenerate.Count} new chunks at a rate of {elapsedMS / chunksToGenerate.Count} ms per chunk!"); } }
private bool Calculate(HexCell currentCell, Vector3Int target, int level) { // termnial : Path not found if (openCell.Count == 0 || level > maxLevel) { return(false); } // store for tracking closedCell.Add(currentCell); // mask current cell visited closedIndex.Add(mapIns.ConvertToIndex(currentCell.X, currentCell.Y)); openCell.RemoveAt(openCell.IndexOf(currentCell)); // check goal Vector3Int currentPos = new Vector3Int(currentCell.X, currentCell.Y, 0); if (currentPos == target) { return(true); } // add neigbours to queue Vector3Int[] neighbours = mapIns.GetNeighboursRange1(currentPos); for (int i = 0; i < neighbours.Length; i++) { HexCell cell = Singleton.Instance <PoolHexCell>().CreateCell(neighbours[i].x, neighbours[i].y); if (cell == null) { continue; // pool empty } if (!closedIndex.Contains(mapIns.ConvertToIndex(cell.X, cell.Y))) { cell.G = currentCell.G + 1; cell.H = Vector3Int.Distance(neighbours[i], target); cell.Parent = currentCell; openCell.Add(cell); } else { Singleton.Instance <PoolHexCell>().Reset(cell); } } // find next node has min F HexCell nextVisit = openCell.Count > 0 ? openCell[0] : null; for (int i = 1; i < openCell.Count; i++) { HexCell checkingCell = openCell[i]; if (checkingCell.F <= nextVisit.F) { if (checkingCell.H < nextVisit.H) { nextVisit = checkingCell; } } } return(Calculate(nextVisit, target, level + 1)); }
/// <summary> /// Gets the length of this path by calculating the distance between all the points /// </summary> /// <returns>The length of the path</returns> public float GetPathLength() { if (pathLength > -1) { return(pathLength); } if (!IsGenerated()) { return(-1); } else if (pathpoints.Count == 0) { return(-1); } float dist = 0; Vector3Int lastPoint = pathpoints[0]; for (int i = 1; i < pathpoints.Count; i++) { dist += Vector3Int.Distance(lastPoint, pathpoints[i]); } pathLength = dist; return(pathLength); }
//Moves greedily towards the target cell based on a straight-line-distance heuristic to the goalCellPos protected Vector3Int GetNextTargetCellTowardsGoal(Vector3Int goalCellPos, Vector3Int previousCellPos, Vector3Int currentCellPos) { var candidateCellTargets = GetCandidateCellTargets(previousCellPos, currentCellPos); if (candidateCellTargets.Count > 1) { (Direction Direction, Vector3Int Pos)closestCandidate = (Direction.None, Vector3Int.zero); float shortestDistance = float.PositiveInfinity; foreach (var candidate in candidateCellTargets) { var dist = Vector3Int.Distance(candidate.Pos, goalCellPos); if (dist < shortestDistance || (dist == shortestDistance && candidate.Direction < closestCandidate.Direction)) { closestCandidate = candidate; shortestDistance = dist; } } return(closestCandidate.Pos); } else if (candidateCellTargets.Count == 1) { return(candidateCellTargets[0].Pos); } return(currentCellPos); }
private Vector3Int GetChasePoint() { switch (ghostType) { case GhostType.Red: return(pacman.CurrentCell); case GhostType.Yellow: if (Vector3Int.Distance(moveLogic.GetCurrentCell(), pacman.CurrentCell) < 8) { return(GetScatterPoint()); } else { return(pacman.CurrentCell); } case GhostType.Magenta: return(pacman.CurrentCell + (pacman.Direction * 4)); // four cells ahead of pacman case GhostType.Cyan: var target1 = pacman.CurrentCell + (pacman.Direction * 2); return(target1 + (target1 - redGhost.CurrentCell)); default: throw new InvalidDataException("Unknown ghost type."); } }
private float SearchHeuristic(PathData path, Vector3Int gridPosition, Vector3 targetDirection) { Vector3 direction = ((Vector3)(path.targetGridPos - gridPosition)).normalized; float targetAlignment = 1.0f - Vector3.Dot(direction, targetDirection); return(Vector3Int.Distance(gridPosition, path.targetGridPos) + targetAlignment); }
/// <summary> /// Sorts the boundary voxels clockwise /// </summary> /// <returns></returns> public void CalculateSortedBoundary() { //var bv = Voxels.Where(v => //v.GetFaceNeighbours() //.Any(n => !Voxels.Contains(n)) //|| v.GetFaceNeighbours().ToList().Count < 4).ToArray(); var boundaryIndexes = BoundaryVoxels.Select(v => v.Index).ToList(); //Vector3 origin = new Vector3( //boundaryIndexes.Average(i => (float)i.x), //0, //boundaryIndexes.Average(i => (float)i.z)); //Array.Sort(boundaryIndexes, new ClockwiseComparer(origin)); //SortedBoundary = boundaryIndexes; Vector3Int[] sortedResult = new Vector3Int[boundaryIndexes.Count]; int i = 0; var current = boundaryIndexes[0]; sortedResult[0] = current; boundaryIndexes.RemoveAt(0); while (boundaryIndexes.Count > 0) { i++; var next = boundaryIndexes.MinBy(v => Vector3Int.Distance(current, v)); sortedResult[i] = next; current = next; boundaryIndexes.Remove(next); //sortedResult. } SortedBoundaryIndexes = sortedResult; }
private void AddComa(Vector3Int center, int radius) { for (int r = 1; r <= radius; ++r) { for (int x = -r; x <= r; ++x) { for (int y = -r; y <= r; ++y) { for (int z = -r; z <= r; ++z) { Vector3Int pos = new Vector3Int(center.x + x, center.y + y, center.z + z); if (!world.IsVoxelInWorld(pos)) { continue; } Vector2Int ChunkCoord = world.GetChunkCoord(pos); Vector2Int InChunkCoord = world.GetInChunkCoord(pos); if (Vector3Int.Distance(center, pos) <= radius && world.Chunks[ChunkCoord.x, ChunkCoord.y].Voxels[InChunkCoord.x, pos.y, InChunkCoord.y] == 0) { world.Chunks[ChunkCoord.x, ChunkCoord.y].Voxels[InChunkCoord.x, pos.y, InChunkCoord.y] = 13; } } } } } }
private void OnMouseDragEnd() { if (draggingCell == null || draggingCell.z == -1) { return; } var ball = balls[draggingCell.x, draggingCell.y]; if (ball == null) { return; } ball.transform.localPosition = grid.CellToLocal(draggingCell); try { Vector3 curPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) + dragOffset; var curCell = grid.WorldToCell(curPosition); var origPosition = grid.CellToWorld(draggingCell); var dist = Vector3Int.Distance(curCell, draggingCell); if (dist < 1.5f) { Move(draggingCell, curCell); // clicked = new Vector3Int(0, 0, -1); } } finally { draggingCell = new Vector3Int(0, 0, -1); } }
/// <summary> /// 增加矿石 /// </summary> /// <param name="randomData"></param> /// <param name="addRate"></param> /// <param name="blockType"></param> /// <param name="startPosition"></param> public static void AddOre(uint randomData, float addRate, Vector3Int startPosition) { //生成概率 float addRateRandom = WorldRandTools.GetValue(startPosition, randomData); if (addRateRandom < addRate) { //高度 int range = 2; //不能直接用 startPosition 因为addRateRandom 的概率已经决定了他的值 int randomOre = WorldRandTools.Range(0, arrayBlockOre.Length, new Vector3(startPosition.x, 0, 0)); for (int x = -range; x < range; x++) { for (int y = -range; y < range; y++) { for (int z = -range; z < range; z++) { Vector3Int blockPosition = new Vector3Int(startPosition.x + x, startPosition.y + y, startPosition.z + z); float disTemp = Vector3Int.Distance(blockPosition, startPosition); if (blockPosition.y <= 3 || disTemp >= range - 0.5f) { continue; } WorldCreateHandler.Instance.manager.AddUpdateBlock(blockPosition, arrayBlockOre[randomOre]); } } } } }
private Vector3Int getRandomEnemyPos(int cellWidth, int cellHeight) { int minX = -blocksWide / 2 + cellWidth / 2; int maxX = blocksWide / 2 - cellWidth / 2; int minY = -blocksHigh / 2 + cellHeight / 2; int maxY = blocksHigh / 2 - cellHeight / 2; bool isTooCloseToCharacter; Vector3Int enemyPosition; do { isTooCloseToCharacter = false; int randXCoord = Mathf.RoundToInt(Random.Range(minX + 1, maxX)); int randYCoord = Mathf.RoundToInt(Random.Range(minY + 1, maxY)); enemyPosition = new Vector3Int(randXCoord, randYCoord, 0); if (CharacterManager.instance != null) { foreach (GameObject character in CharacterManager.instance.charactersList) { Vector3Int charPosition = grid.LocalToCell(character.transform.localPosition); if (Vector3Int.Distance(enemyPosition, charPosition) < 8) { isTooCloseToCharacter = true; } } } } while (isTooCloseToCharacter); return(enemyPosition); }
private static void FindTilesInRange(HashSet <Vector3Int> affectedTiles, Hashtable characters, int team, Vector3Int currentPosition, int range) { for (int range_x = 0; ; range_x++) { for (int range_y = 0; ; range_y++) { Vector3Int rangePosition = new Vector3Int(currentPosition.x + range_x, currentPosition.y + range_y, currentPosition.z); int distance = Mathf.RoundToInt(Vector3Int.Distance(currentPosition, rangePosition)) * tileCost; if (distance <= range) { for (int x = currentPosition.x - range_x; x <= currentPosition.x + range_x; x += range_x) { for (int y = currentPosition.y - range_y; y <= currentPosition.y + range_y; y += range_y) { counter++; Vector3Int availablePosition = new Vector3Int(x, y, currentPosition.z); Character characterAtPosition = gameController.CharacterAtPosition(availablePosition); if (characterAtPosition) { if (characterAtPosition.Team != team && characterAtPosition.Conscious && !characters.Contains(availablePosition)) { characters.Add(availablePosition, characterAtPosition); } } if (!characterAtPosition && !TilemapContainsPosition(impassableTerrain, availablePosition) && !affectedTiles.Contains(availablePosition)) { affectedTiles.Add(availablePosition); } if (range_y == 0) { break; } } if (range_x == 0) { break; } } } else { break; } } if (Vector3Int.Distance(currentPosition, new Vector3Int(currentPosition.x + range_x, currentPosition.y, currentPosition.z)) * tileCost > range) { break; } } }
protected static void AddCaveRange(Vector3Int startPosition, int caveRange, int type, int lastType) { if (type == lastType) { for (int a = -caveRange; a <= caveRange; a++) { for (int b = -caveRange; b <= caveRange; b++) { Vector3Int blockPosition; switch (type) { //x case 1: blockPosition = new Vector3Int(startPosition.x, startPosition.y + a, startPosition.z + b); break; //y case 2: blockPosition = new Vector3Int(startPosition.x + a, startPosition.y, startPosition.z + b); break; //z case 3: blockPosition = new Vector3Int(startPosition.x + a, startPosition.y + b, startPosition.z); break; default: blockPosition = new Vector3Int(startPosition.x, startPosition.y, startPosition.z); break; } float disTemp = Vector3Int.Distance(blockPosition, startPosition); if (blockPosition.y <= 3 || disTemp >= caveRange - 0.5f) { continue; } WorldCreateHandler.Instance.manager.AddUpdateBlock(blockPosition, BlockTypeEnum.None); } } } else { for (int a = -caveRange; a <= caveRange; a++) { for (int b = -caveRange; b <= caveRange; b++) { for (int c = -caveRange; c <= caveRange; c++) { Vector3Int blockPosition = new Vector3Int(startPosition.x + a, startPosition.y + b, startPosition.z + c); float disTemp = Vector3Int.Distance(blockPosition, startPosition); if (blockPosition.y <= 3 || disTemp >= caveRange - 0.5f) { continue; } WorldCreateHandler.Instance.manager.AddUpdateBlock(blockPosition, BlockTypeEnum.None); } } } } }
private IEnumerator ExplosionRoutine(Matrix matrix) { var explosionCenter = transform.position.RoundToInt(); // First - play boom sound and shake ground PlaySoundAndShake(explosionCenter); // Now let's create explosion shape int radiusInteger = (int)radius; var shape = EffectShape.CreateEffectShape(explosionType, explosionCenter, radiusInteger); var explosionCenter2d = explosionCenter.To2Int(); var tileManager = GetComponentInParent <TileChangeManager>(); var longestTime = 0f; foreach (var tilePos in shape) { float distance = Vector3Int.Distance(tilePos, explosionCenter); var tilePos2d = tilePos.To2Int(); // Is explosion goes behind walls? if (IsPastWall(explosionCenter2d, tilePos2d, distance)) { // Heat the air matrix.ReactionManager.ExposeHotspotWorldPosition(tilePos2d, 3200, 0.005f); // Calculate damage from explosion int damage = CalculateDamage(tilePos2d, explosionCenter2d); if (damage > 0) { // Damage poor living things DamageLivingThings(tilePos, damage); // Damage all objects DamageObjects(tilePos, damage); // Damage all tiles DamageTiles(tilePos, damage); } // Calculate fire effect time var fireTime = DistanceFromCenter(explosionCenter2d, tilePos2d, minEffectDuration, maxEffectDuration); var localTilePos = MatrixManager.WorldToLocalInt(tilePos, matrix.Id); StartCoroutine(TimedFireEffect(localTilePos, fireTime, tileManager)); // Save longest fire effect time if (fireTime > longestTime) { longestTime = fireTime; } } } // Wait until all fire effects are finished yield return(WaitFor.Seconds(longestTime)); Destroy(gameObject); }
public Neighbour(Vector3Int position, bool walkable, Vector3Int target = new Vector3Int()) { this.position = position; this.distanceToTarget = Vector3Int.Distance(target, position); this.walkable = walkable; }
// Use this for initialization public void setPoints(Vector3Int[] vcts) { //Initialisation de points pour la démonstration RoadListPoint = vcts; //Initialisation Distance et Position en Int PeoplePosition = new Vector3Int((int)transform.position.x, (int)transform.position.y, (int)transform.position.z); DistanceNextPoint = (int)Vector3Int.Distance(PeoplePosition, RoadListPoint[i]); }