Godot Version
v4.6.stable.official [89cea1439]
I want to make my Control node move slightly up, whenver a mouse eneters button node, and whenever mouse leaves the button node, i want it go to the orginal place. The issue is that i dont know where button should move back after being lifted up. I cant just move it to its position+position_offset cause if it was lifted multiple times it will not come back to the original place. Is there any easy way to do it? Is there any simple solution?
extends Control
class_name Playmode
@export var position_offset: Vector2 = Vector2(0, 50)
@onready var button: Button = $Button
# var trigerred: int = 0
var previous_pos: Vector2
func _ready() -> void:
button.pressed.connect(_on_button_pressed)
button.mouse_entered.connect(_on_mouse_entered)
button.mouse_exited.connect(_on_mouse_exited)
func _on_button_pressed():
playmode_button_pressed.emit()
func _on_mouse_entered():
tween = get_tree().create_tween()
previous_pos = position
tween.tween_property(self, "position", position-position_offset, 0.5)
await tween.finished
tween.kill()
tween = null
func _on_mouse_exited():
tween = get_tree().create_tween()
tween.tween_property(self, "position", previous_pos, 0.5)
await tween.finished
tween.kill()
tween = null