This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

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
in Engine by (43 points)

1 Answer

+1 vote

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

by (268 points)

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?

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.