im using godot version 4.6.1, i have this problem where i want to tween this enemy towards the player’s mouse, but it always goes to the top left, then starts doing weird small movements, heres the code for the function (it gets activated once a timer runs out)
func do_dash_attack():
var direction = (get_global_mouse_position() - position).normalized() * 300
var tween = get_tree().create_tween()
tween.set_trans(Tween.TRANS_LINEAR)
tween.tween_property(self,"global_position",direction,0.5)
tween.play()
Two things, for one, you are mixing global_position with position. They are different. position is local to that node, while global_position is, well, global.
Another thing is that the “direction” in your case is more of an offset rather than the actual direction. You should take the global_position and add the offset to it.
Something like this (this might not work, but you can get an idea from it)
func do_dash_attack():
var offset = (get_global_mouse_position() - global_position).normalized() * 300
var target_position = global_position + offset
var tween = get_tree().create_tween()
tween.set_trans(Tween.TRANS_LINEAR)
tween.tween_property(self,"global_position",target_position,0.5)
Also small PS: No need to call play() on the tween, it’ll play anyway so it’s redundant.