0 votes

I am trying to have player walk towards a destination defined by the click of the mouse.
But although the coordinates of the input even and the points seem to be right
The path followed is all wrong.

func _unhandled_input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.pressed:
            path = $Navigation2D.get_simple_path($Player.position, event.position)
            $Player.path = path         
            $Line2D.points = path
            print(path.size(), ' Path:',path, '  Player:', $Player.position, '  Target:', event.position)           
            update()  # so line and circles get drawn


func _draw():
    for p in path:
                draw_circle(p, 5, Color(200, 200, 200))

Very minimal demo here
Any help appreciated!

Github repo

Video

in Engine by (16 points)
edited by

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.