Why Button not working after Tween?

Godot Version

v4.6.1.stable.official [14d19694e]

Question

Why Button not working after Tween?

class_name Player

@onready var player_sprite: AnimatedSprite2D = $PlayerSprite
var tween: Tween

var SPEED = randf_range(0.03, 0.09)
@onready var walk_button: Button = $UI/Control/MarginContainer/Buttons/WalkButton

@export var path_2d: PathFollow2D

func _on_walk_button_pressed() -> void:
	player_sprite.play("WALK")
	_reset_tween()
	tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_ELASTIC)
	tween.tween_property(path_2d,"progress_ratio", SPEED, 0.5)

func _reset_tween() -> void:
	if tween:
		tween.kill()
	tween = create_tween()

“Not working” in what way? Describe the problem in more detail.

1 Like

Movement in my game is triggered by a “walking” button, with the character following a path via the PathFollow2D node. Each button press advances the character by a small segment, implemented as follows:
path_2d.progress_ratio += SPEED (SPEED player’s movement speed).

I attempted to improve the animation by introducing a Tween for smooth walking. However, after implementation, the character performs a single movement and then fails to respond to further button presses.

This is the signature of the tween.tween_property function:

The argument where you put in SPEED is the final value the progress_ratio should have. So you have to set that to the incremental value, otherwise you just reset the ratio to the same value everytime.

2 Likes

Exactly what @dweipert said.
You can also add .as_relative() to your tween_property() line to make it automatically incremental.

3 Likes

Thank you