Tween problem without error message

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zeelox

hi guys :smiley:

i’m new in godot engine and i have a probem with this code :
i want the saibamen to follow the mouse. i don’t have any errors but the sprite don’t move anymore :confused: please help me <3

    extends KinematicBody2D

func _ready():
	set_process(true)
	set_physics_process(true)
	pass

func _process(delta):
	pass
	
func _physics_process(delta):	
	var mouse_pos = get_global_mouse_position()
	var tween = get_node("Tween")
	var saibamen = get_node("Saibamen")
	
	if(Input.is_action_pressed("ui_accept")):
		tween.interpolate_property(saibamen, "Transform/Position", saibamen.position, mouse_pos, 5, tween.TRANS_BACK, tween.EASE_OUT)
		tween.start()
		pass
	pass
:bust_in_silhouette: Reply From: Zylann

Assuming your tween node exists:

    if(Input.is_action_pressed("ui_accept")):
        tween.interpolate_property(saibamen, "Transform/Position", saibamen.position, mouse_pos, 5, tween.TRANS_BACK, tween.EASE_OUT)
        tween.start()

First, it will run only if you press ui_accept (which I assume is the Enter key).

Second, because you are doing this in _physics_process, it will run 60 times per second as long as you keep holding ui_accept. So the tween will try to start but will keep restart over and over, so it won’t move until you let go the key.

Apart from that, I’m not sure what else could cause the sprite to not move… are you sure the inside of the if runs when you press the key?

Unrelated note: you don’t need to write pass.