Pop-up files, need help with movement

Godot Version

godot-4

Question

I have a game system where I have a box full of files(2d, sorta like a point and click game) where I need the files to pop up when the mouse hovers over them. I have a script but it doesn’t seem to be working and I’m not certain why. My file node has an area 2d on it and a collision shape. the area sends a signal to the script that flips a boolean on or off when the mouse enters the area.

extends Sprite2D
@export var openFile: Node2D
var openFileGD = Script
@export var fileSlideAmount = 1
var mouseHovering = false
var startPos = Vector2()
var slidePos = Vector2()

func _ready():
	var startPos = position
	var slidePos = position + Vector2(0, fileSlideAmount)
	openFileGD = openFile.get_script()

func _on_area_2d_input_event(viewport, event, shape_idx):
	if (event is InputEventMouseButton && event.pressed):
		openFile.visible = true

func _process(delta):
	if mouseHovering == true:
		position.move_toward(slidePos,delta * 3)
	else:
		position.move_toward(startPos,delta * 3)

func _on_area_2d_mouse_entered():
	mouseHovering = true

func _on_area_2d_mouse_exited():
	mouseHovering = false


What is your problem? mouseHovering always false? Then tell me the scene tree

I ran some print_debugs and it looks like the mouse is detecting correctly, so it looks like the issue is the movement itself.

I’ve updated the code and now the files slide up and to the left slowly, regardless of if the mouse is hovering over it.

extends Sprite2D
@export var openFile: Node2D
var openFileGD = Script
@export var fileSlideAmount = 1
var mouseHovering = false
var startPos = Vector2()
var slidePos = Vector2()

func _ready():
	var startPos = global_position
	var slidePos = Vector2(global_position.x, global_position.y + 2)
	openFileGD = openFile.get_script()

func _on_area_2d_input_event(viewport, event, shape_idx):
	if (event is InputEventMouseButton && event.pressed):
		openFile.visible = true

func _process(delta):
	if mouseHovering == true:
		global_position = global_position.move_toward(slidePos,delta * 3)
	else:
		global_position = global_position.move_toward(startPos,delta * 3)

func _on_area_2d_mouse_entered():
	mouseHovering = true


func _on_area_2d_mouse_exited():
	mouseHovering = false

Can you print or set breakpoints to determine if mouseHovering is being changed?

Edit: Ninjad

Edit: It looks like SlidePos is just startpos but 2 pixels down? so it’s basically the same?

I think I found the issue, but I don’t know why it’s happening, it seems like the start position and slide position are saving as the world origin rather than the actual position of the node, is there any visible reason why that might be happening?

I just ran a print on the positions and it looks like the variables where the start position and desired position are saved are reseting to 0,0 after _Ready, why is this?