+1 vote

Hi Godot bros, I made a room with a tilemap adding navigation to the tiles. I have an enemy that follows the player using the navigation. If the room I place the room in the origin coordinates 0,0 everything works fine, the problem comes when I move it. The enemy only moves in the zone that would be the room if it was in the origin coordinates

navigation.get_simple_path(global_position, player.position) I get the path with this function, I use the local player position because the player is a direct child of the main scene, the local and global coordinates are the same.

var distance_to_next_point: float = (path[0] - global_position).length()
    if distance_to_next_point < 1:
        path.remove(0)
        if not path:
            return
    var direction: Vector2 = path[0] - global_position
    mov_direction = direction

I use this code to follow the path and I move it with the move_and_slide() function.

Video on Reddit

Maybe the problem is something with the local and global coordinates?

Help me, please!

Godot version 3.3.2
in Engine by (13 points)

Please log in or register to answer this question.

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.
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 webmaster@godotengine.org with your username.