Godot Version
4.5
Question
`I am trying to take a position in a video game I play and translate that into a position on a 2D map I created from taking screenshots of the in-game map and importing them into Godot. In the video game coordinate system, (0,0) is the bottom left. However, the bottom left of the map is around (16384, 24584).
var origin := Vector2(16384, 24584)
I went to two different areas in the game. I noted the position of each in the game and found the corresponding coordinates on the map in Godot.
var game_position_a = Vector2(65963, 81295)
var game_position_b = Vector2(62493, 82578)
var godot_position_a = Vector2(2418, 822)
var godot_position_b = Vector2(3344, 1676)
I found the distance between the two positions.
var game_distance = sqrt(pow(game_position_a.x - game_position_b.x, 2) + pow(game_position_a.y - game_position_b.y, 2))
var godot_distance = sqrt(pow(godot_position_a.x - godot_position_b.x, 2) + pow(godot_position_a.y - godot_position_b.y, 2))
I then get the scale factor.
var scale_factor = game_distance / godot_distance
Multiplying the game position by the scale factor does not give the correct coordinates in Godot.
var godot_scaled_a = game_position_a * scale_factor
var godot_scaled_b = game_position_b * scale_factor
I have tried adding the origin position to the game positions. I have tried subtracting the height of the map in Godot from the y values in the Godot positions. I have tried calculating the scale factor with godot_distance / game_distance.
I’ll admit, I’m in a little over my head, trying to piece together some things I found on Google. Am I even in the ballpark? Is there a better or even different way to do what I am trying to accomplish? Thank you so much for the time you spent reading this post and thanks in advance for any help you can provide.`