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.
0 votes

For the life of me I can't seem to figure out how to get my sprites to move to the correct position. Everything works while moving the camera but adding zoom into the mix just really messes everything up.

When the Actor node detects a LMB click in the _input() method it creates a path to use for to use for pathfinding

func create_path_to_destination(
    event_position: Vector2,
    camera_position: Vector2 = Vector2(0,0)
    path = Navigation2d.get_simple_path(get_position(),
            event_position + camera_position)

Then on every _physics_process(delta) update I run the following code to move the character along the path

func move_to_destination(delta: float) -> void:
    var distance_to_walk = Stats.current_movement_speed * delta
    while distance_to_walk > 0 and path.size() > 0:
    var distance_to_next_point = position.distance_to(path[0])
        if distance_to_walk <= distance_to_next_point:
            # warning-ignore:return_value_discarded
                    position.direction_to(path[0]) * Stats.current_movement_speed)
    distance_to_walk -= distance_to_next_point

Again, this all works perfectly fine even if I move the camera but after zooming in or out is when this begins to break.

Godot version 3.3.3.stable
in Engine by (15 points)

1 Answer

+1 vote
Best answer

var position = event.position * camera.zoom
try it , hope it helps

by (274 points)
edited by

As a follow up question if you happen to see this, how did you know that would work? Does that knowledge come from your own personal experience with something similar or is it just general math skills that I am lacking?

personal experience , dealing with control nodes and nodes2d while each one have a different space is tricky and this is one of the common problems that you will deal with , because control nodes position is using screen position and node2d or node3d are using world positions.

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.