Godot Version
Godot 4.2
Question
I’ve been trying to make a simple throw mechanic for a top-down 2D game, where a held item is thrown towards the mouse cursor. As I understand it, this should be done with something like
var velocity_vector = (get_global_mouse_position() - global_position).normalized()
apply_central_impulse(velocity_vector * modifier)
However, the global_position of the held item is always the same when I press throw, so it always goes in the wrong direction.
I checked this with print statements -
func _process(delta):
print(global_position)
func throw():
print("global_position: " + var_to_str(global_position))
which shows the discrepancy between the global_position values -
The value printed by _process() updates & changes every frame correctly, but no matter how many times I press throw when I move, the global_position is always (92,1). I want to access the global_position being printed by _process() to calculate the throw, does anyone know how to do that?
I think this is due to the difference in Viewport vs CanvasLayer coords after I found Viewport and canvas transforms — Godot Engine (stable) documentation in English, but after trying a ton of different conversions I still can’t seem to find the right global_position I want If anyone has more info on how I can do this, I would really appreciate it