public void OnUpdate() { IM.ResetMap(MapType.Npc); foreach (Npc npc in Npcs.Values) { IM.CalculateMap(); //this should be optimezed to only multiple updated npc map pos with the same grid from start of frame Vector2Int temp = npc.GridPosition; if (npc.Path.Count < 1 && npc.GridPosition != npc.Goal) { npc.Path = InfluenceAStar.GetPath(npc.GridPosition, npc.Goal).ToList(); } else { npc.Path = InfluenceAStar.RecalculatePath(npc.GridPosition, npc.Path); } if (npc.Path.Count > 4) { for (int i = 0; i < 4; i++) { IM.DrawOnMap(MapType.Npc, npc.Path[i].x, npc.Path[i].y, 0f); } } if (Vector3.Distance(npc.transform.position, npc.TargetLocation) < 0.1f) { if (npc.Path.Count > 0) { npc.Path.RemoveAt(0); } if (npc.Path.Count < 1) { continue; } //npc.TargetLocation = InfluenceMapper.MP.DrawPos[0][npc.Path[0].x][npc.Path[0].y]; npc.TargetLocation = IM.GridToWorld(npc.Path[0]); } npc.transform.position = Vector3.Lerp(npc.transform.position, npc.TargetLocation, npc.Speed * Time.deltaTime); Debug.DrawLine(npc.transform.position, npc.TargetLocation, Color.magenta); } }
public void OnUpdate() { MoveHazard(); IM.ResetMap(MapType.Hazard); foreach (Hazard hazard in _hazards) { if (!hazard.Modified) { continue; } Vector2Int newPos = IM.WorldToGrid(hazard.transform.position); IM.DrawCircleOnMap(MapType.Hazard, newPos.x, newPos.y, hazard.Radius, hazard.MapValue); hazard.Modified = false; } }