- Home /
I was able to figure out the answer a while ago, and nobody has answered this question in almost a month, so why keep it open
AOE damage on tilemaps?
Bit of a weird question, so I'll go into more detail.
I'm working on what's basically a fossil cleaning simulation, where you use various tools to break through layers of rock and clean the fossil, without damaging it too much. Each layer of the rock is its own tilemap, and each tile holds data for health and position, with classes and dictionaries. Currently, the player is able to use a drill to break singular tiles, or sections of the rock. However, due to how I set everything up, I'm not sure how to go about adding a "hammer" effect. The goal of the hammer would be to hit multiple tiles at once, in a concentric circle pattern. The innermost part of the circles would ideally deal the most damage to the layers of rock, and the outer rings would deal less damage, but are more spread out. It'd probably be best to give an example, so here's what I'm trying to simulate with this whole project. https://www.youtube.com/watch?v=ws-TA4PniJk
Currently, I have everything working except for the hammer. In a script on my Grid, the way I have the individual tiles set up is as follows:
public Tilemap Tilemap1
int TileHealth1
tiles1 = new Dictionary<Vector3, WorldTile>();
foreach (Vector3Int pos in Tilemap1.cellBounds.allPositionsWithin)
{
var localPlace = new Vector3Int(pos.x, pos.y, pos.z);
if (!Tilemap1.HasTile(localPlace)) continue;
var tile = new WorldTile
{
LocalPlace = localPlace,
Layer = 1,
WorldLocation = Tilemap1.CellToWorld(localPlace),
TileBase = Tilemap1.GetTile(localPlace),
TilemapMember = Tilemap1,
Name = localPlace.x + "," + localPlace.y,
Health = TileHealth1
};
tiles1.Add(tile.WorldLocation, tile);
}
WorldTiles is the class that I take information from. For the drill script, here's a code sample.
var tiles = GameTiles.instance.tiles1;
if (Input.GetMouseButton(0))
{
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var worldPoint = new Vector3Int(Mathf.FloorToInt(point.x), Mathf.FloorToInt(point.y), 0);
if (tiles1.TryGetValue(worldPoint, out _tile))
{
print("Tile " + _tile.Name + "Layer: " + _tile.Layer + "health: " + _tile.Health);
_tile.Health -= 1;
_tile.TilemapMember.SetTileFlags(_tile.LocalPlace, TileFlags.None);
if (_tile.Health <= 0)
{
_tile.TilemapMember.SetTile(_tile.LocalPlace, null);
tiles1.Remove(_tile.LocalPlace);
}
}
This is repeated for every layer, with else if statements making it so the drill only hits one layer/tilemap of rock at a time.
The question now is how to implement a way to deal damage to the tilemaps in concentric circles, without starting over and setting everything up differently. I don't even know where to start on something like this, so any help is greatly appreciated. I think the tilemap method that I set up is a pretty good way to simulate fossil cleaning, but if someone has experience with damaging tilemaps in this sort of way I'd appreciate any advice I can get.
Follow this Question
Related Questions
Screen flashes red when taking damage 3 Answers
How do I simulate a tsunami wave? 6 Answers
Object Not Recieving Damage 3 Answers
Expecting ) found = 1 Answer