2D pathfinding - NavMesh or TileSet issue

Godot Version

4.3.stable.official [77dcf97d8] (steam)

Question

I’m having an issue moving a player character.

I picked up a project I started a couple months back. It ran fine, without issue.
I replaced the spritesheet in its tilemap, set up every tiles navigation and physics, and swapped the TileMap node for a TileMapLayer node in the scene.

In game when I click to move the player character I get a debug line to the location clicked and the console prints out my velocity suggesting I should be moving as the following line is move_and_slide(), but the character isn’t. I should add that the player character class extends CharacterBody2D.

I thought maybe I setup the navigation layer incorrectly. It looks alright in game though.

I only have 1 layer, no patterns.

Tiles are set during runtime.

Every 10 or so seconds the yellow square (which I’m using to represent the player character) jitters which makes me think this is a nav mesh issue.

As a new user to the forum I’m only able to embed one link, so here’s a link to a bunch of pictures which should help visualise what’s going on.

It cant be a navmesh or pathfinding issue when the debug path shows up a correct path like in that image because that is the loaded path of the agent.

Physics and movement script issues are more likely. Query a normal path from the NavigationServer with map_get_path() and move something along this path without physics involved to confirm this. This will help you to narrow down the problem.

1 Like

I assume you mean something like this.

func _on_chunk_clicked(coordinates, worldPosition):
	#make_path(worldPosition)
	var map: RID = tile_map_layer.get_navigation_map()
	path = NavigationServer2D.map_get_path(map, position, worldPosition, false ) as Array
	pass

func _process(delta: float) -> void:
	if path.size() > 0:
		position.move_toward(path[0], delta * 10.0)
		if position.distance_to(path[0]) < 3.0:
			path.remove_at(0)

It is returning a path but the player still doesn’t move along it.
image

	var map: RID = NavigationServer2D.map_create()
	path = NavigationServer2D.map_get_path(map, position, worldPosition, false ) as Array

throws:

PlayerCharacter.gd:26 @ _on_chunk_clicked(): NavigationServer navigation map query failed because it was made before first map synchronization.
NavigationServer ‘map_changed’ signal can be used to receive update notifications.
NavigationServer ‘map_get_iteration_id()’ can be used to check if a map has finished its newest iteration.

https://i.imgur.com/moIlTNX.gif

That error is because you need to give the NavigationServer time to sync the navigation map, else you query just an empty map.

See NavigationServer synchronisation Using NavigationServer — Godot Engine (latest) documentation in English

1 Like

alright - I figured it out. I loaded up the earlier version of the project and compared how I was setting up the TileSets and found that the older version didn’t have vertices painted on the physics layer. Removing them resolved the issue.

Cheers for the help all that same, Smix :saluting_face:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.