0 votes

HI all!

I'm new to Godot so still figuring some things out.

I have a scene like this:
enter image description here
The camera is set to follow the sprite node. When I click on the game, I want the sprite to move to the position I have clicked on the tilemap but it always goes to somewhere different. What global/viewport/local conversion voodoo do I need to do to get the sprite to move to where I have clicked on the tilemap?

Thanks!

in Engine by (14 points)
edited by

Can you show us the code you currently have for moving your sprite?
Are you moving it onto a cell on the tilemap or just somewhere in the world?

1 Answer

0 votes

I have never used Navigation2D nor do I know what exactly it is that you wish to achieve here, but a simple way to just move your sprite to the desired coordinates is to simply instruct it to move to the global position of the mouse. Go to the project settings and under Input Map create a new mouse input, name it "mouse_click" and use the following code in the Sprite's script:

func _process(delta):
    if Input.is_action_just_released("mouse_click"):
        position = get_global_mouse_position()

Unless there is any particular reason why this wouldn't work with Navigation2D and Tilemaps or you want something more sophisticated, this will do.

by (1,850 points)
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.