+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
asked Apr 16 in Engine by MaxEl777 (41 points)

1 Answer

+1 vote

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

answered Apr 16 by caprinae (266 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 How to use this Q&A? before posting your first questions.