Topic was automatically imported from the old Question2Answer platform.
Asked By
doinsdf
I’m trying to have a certain thing happen when the player gets close enough to an object:
if position.distance_to(g.playerpos) <= 200:
sf = true
(‘g’ is my global script’s variable.)
Here’s the error I get:
Invalid type in function 'distance_to' in base 'Vector2'. Cannot convert argument 1 from int to Vector2.
But… position is already a Vector2!
Could somebody help me out here? Thanks.
So, position is Vector2, but what about g.playerpos? Can you show us the code where you defined that in the global script, and any line of code where you may modify it?
exactly, position is vector2(), you’re saying
if Vector2(x, y) <= 200… it’s not possible to know if 200 is in x or y axis
you can define position as x or y (position.x <= 200) or position <= Vector2(200, 0)