Weird disjoint between main scene and instance scene positions

Version

4.1.1

tying to make a plants vs zombies type game and when instancing a unit from a button and have it follow the mouse the coordinates for the object and the mouse are the same but their actual position is weirdly disjointed and the farther the mouse gets from the origin the more separated they become, been at this for a few hours and haven’t found a working solution and i recorded a video but i just made my account to get help so it wont let me upload it yet :unamused:. would love to know why this happens and how i can prevent it.

It sounds like you’re mixing global coordinates with local coordinates.

1 Like

i was suspecting it was something like that but i dont know how to differentiate them and fix it and right now im just using viewport coordinates

To get the mouse’s global position:

var mouse : Vector2 = get_global_mouse_position()

Then instantiate your unit and set its global position to your mouse’s global position:

unit.global_position = mouse

1 Like

that worked perfectly!!! I tried something like that earlier but i didnt know about .global_position, thanks for the tip :+1: :+1: :+1: