Minor changes
parent
5bbcb41011
commit
13ef93cedd
|
@ -11,7 +11,10 @@ func _physics_process(delta: float) -> void:
|
||||||
nav.target_position = get_global_mouse_position()
|
nav.target_position = get_global_mouse_position()
|
||||||
|
|
||||||
movement = nav.get_next_path_position() - global_position
|
movement = nav.get_next_path_position() - global_position
|
||||||
movement = movement.normalized() * ACCELERATION
|
if movement.length() < 20:
|
||||||
|
movement = -velocity * 0.2
|
||||||
|
else:
|
||||||
|
movement = movement.normalized() * ACCELERATION
|
||||||
|
|
||||||
velocity += movement
|
velocity += movement
|
||||||
if velocity.length() > MAX_SPEED:
|
if velocity.length() > MAX_SPEED:
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
extends Node2D
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
var physics_tilemap = $Fence
|
|
||||||
var navigation_tilemap = $Grass
|
|
||||||
var tile_set = physics_tilemap.tile_set
|
|
||||||
if not tile_set:
|
|
||||||
print("Failed to find tile_set on physics_tilemap")
|
|
||||||
return
|
|
||||||
|
|
||||||
var tile_size = tile_set.get_tile_size()
|
|
||||||
var used_rect = physics_tilemap.get_used_rect()
|
|
||||||
print(used_rect)
|
|
||||||
|
|
||||||
for x in range(used_rect.position.x, used_rect.size.x):
|
|
||||||
for y in range(used_rect.position.y, used_rect.size.y):
|
|
||||||
var tile_id = physics_tilemap.get_cell(x, y)
|
|
||||||
if tile_id == -1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Get the collision shapes for the current tile
|
|
||||||
var collision_shapes = tile_set.tile_get_shapes(tile_id)
|
|
||||||
if not collision_shapes:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Convert collision shapes into NavigationPolygon cut-outs
|
|
||||||
for shape in collision_shapes:
|
|
||||||
if shape.shape.is_class("RectangleShape2D"): # assuming rectangle shapes for simplicity
|
|
||||||
var rect = Rect2(
|
|
||||||
Vector2(x, y) * tile_size,
|
|
||||||
Vector2(shape.shape.extents) * 2
|
|
||||||
)
|
|
||||||
cut_navigation_polygon(navigation_tilemap, rect)
|
|
||||||
# Expand this if-else for other shapes like CircleShape2D, etc.
|
|
||||||
|
|
||||||
func cut_navigation_polygon(navigation_tilemap: TileMapLayer, rect: Rect2):
|
|
||||||
for nav_polygon in navigation_tilemap.get_children():
|
|
||||||
if nav_polygon.is_class("NavigationPolygonInstance"):
|
|
||||||
# This is a crude example - in practice, create new polygons to adjust the navigation mesh
|
|
||||||
var nav_rect = nav_polygon.get_item_rect()
|
|
||||||
if nav_rect.intersects(rect):
|
|
||||||
# Here, define logic to cut rect from nav_rect, adjusting navigation mesh
|
|
||||||
# Example: Remove affected navigation polygon and recreate it around `rect`
|
|
||||||
nav_polygon.remove() # remove or edit as per your exact cutout needs
|
|
||||||
# Note: Fine-tuning would involve more detailed polygon edits or re-creation.
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue