make the orientation of obstacle align with four side of cell on gridmap
This commit is contained in:
+22
-6
@@ -851,9 +851,9 @@ func highlight_movement_range():
|
||||
|
||||
var cells_to_highlight = []
|
||||
|
||||
# Only highlight cells within movement range that aren't blocked by obstacles
|
||||
for x in range(enhanced_gridmap.columns):
|
||||
for z in range(enhanced_gridmap.rows):
|
||||
# For each position within movement range
|
||||
for x in range(max(0, current_position.x - movement_range), min(enhanced_gridmap.columns, current_position.x + movement_range + 1)):
|
||||
for z in range(max(0, current_position.y - movement_range), min(enhanced_gridmap.rows, current_position.y + movement_range + 1)):
|
||||
var test_pos = Vector2i(x, z)
|
||||
|
||||
# Skip the current position
|
||||
@@ -864,10 +864,26 @@ func highlight_movement_range():
|
||||
if is_within_movement_range(test_pos):
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
|
||||
|
||||
# Check if cell is walkable and not occupied
|
||||
# Basic walkability check
|
||||
if cell_item != -1 and not (cell_item in enhanced_gridmap.non_walkable_items) and not is_position_occupied(test_pos):
|
||||
# Most importantly, check if movement is blocked by obstacles
|
||||
if not enhanced_gridmap.is_blocked_by_obstacle(current_position, test_pos, 3):
|
||||
# Check if there's a direct path without obstacles
|
||||
var path_blocked = false
|
||||
|
||||
# For orthogonal movement
|
||||
if test_pos.x == current_position.x or test_pos.y == current_position.y:
|
||||
path_blocked = enhanced_gridmap.is_blocked_by_obstacle(current_position, test_pos, 3)
|
||||
else:
|
||||
# For diagonal movement, check if both orthogonal paths are blocked
|
||||
var mid1 = Vector2i(test_pos.x, current_position.y)
|
||||
var mid2 = Vector2i(current_position.x, test_pos.y)
|
||||
|
||||
var path1_blocked = enhanced_gridmap.is_blocked_by_obstacle(current_position, mid1, 3)
|
||||
var path2_blocked = enhanced_gridmap.is_blocked_by_obstacle(current_position, mid2, 3)
|
||||
|
||||
# Only completely block if both paths are blocked
|
||||
path_blocked = path1_blocked and path2_blocked
|
||||
|
||||
if not path_blocked:
|
||||
cells_to_highlight.append(test_pos)
|
||||
|
||||
highlight_cells_if_authorized(cells_to_highlight)
|
||||
|
||||
Reference in New Issue
Block a user