Path finding in a tilemap generated at runtime.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MaxEl777

I use Navigation2D to navigate in a tilemap generated at runtime. However, the wayfinding does not work properly the object the wayfinding is applied to never runs the direct way and often gets stuck on collision tiles. I use simple single tiles with a navigation rectangle on top.

That’s the code I use to follow the trail:

if start_moving_to_destination: 
	if path.size() >= 1:
		var velocity = (path[0] - position).normalized() * speed
		var applied_velocity = move_and_slide(velocity)
		if position.distance_to(path[0]) < 2:
			path.remove(0)
	else:
		start_moving_to_destination = false
:bust_in_silhouette: Reply From: caprinae

Are you sure you’re calling update_dirty_quadrants() after you generate or modify the tilemap?

Thank you for your quick response. Pathfinding works better now, but somehow still doesn’t always take the direct way and gets stuck at corners of tiles with collision enabled.
Do you know a solution?

MaxEl777 | 2020-04-16 21:16

Sorry, I don’t know much about how Navigation2D works. If your object is getting stuck on collisions, maybe try tweaking the collision shape.

caprinae | 2020-04-16 21:22