Godot Version
4.2
Question
I have a battle scene and an enemy scene that gets instantiated inside the battle scene.
The enemy scene has a target marker that is hidden by default.
My goal is to make the marker pop up (show itself) whenever the player hovers over the enemy with their mouse cursor and hide itself, when the cursor exited.
Here’s enemy script:
extends Area2D
@onready var target_marker = $TargetMarker
func _on_mouse_entered():
emit_signal("mouse_entered")
target_marker.show()
func _on_mouse_exited():
emit_signal("mouse_exited")
target_marker.hide()
And here’s battle scene script:
extends Node2D
@onready var pos1 = $Position1
@onready var pos2 = $Position2
@onready var pos3 = $Position3
@onready var pos4 = $Position4
@onready var pos5 = $Position5
var wooddog_PLOAD = preload("res://scenes/characters/enemies/wooden_doggo.tscn")
var watersprite_PLOAD = preload("res://scenes/characters/enemies/water_sprite.tscn")
var mushroom_PLOAD = preload("res://scenes/characters/enemies/mushroom.tscn")
var bikini_PLOAD = preload("res://scenes/characters/enemies/bikini.tscn")
var enemy_num = [1, 2, 3, 4]
var enemies = [
wooddog_PLOAD,
wooddog_PLOAD,
wooddog_PLOAD,
wooddog_PLOAD,
wooddog_PLOAD,
watersprite_PLOAD,
watersprite_PLOAD,
watersprite_PLOAD,
mushroom_PLOAD,
mushroom_PLOAD,
mushroom_PLOAD,
bikini_PLOAD
]
var positions = [pos1, pos2, pos3, pos4]
var enemy_group = []
var pos1_taken = false
var pos2_taken = false
var pos3_taken = false
var pos4_taken = false
# Called when the node enters the scene tree for the first time.
func _ready():
for enemy in range(enemy_num.pick_random()):
enemy_group.append(enemies.pick_random())
for enemy in enemy_group:
if enemy == wooddog_PLOAD:
var wooddog_ins = wooddog_PLOAD.instantiate()
if pos1_taken == false:
wooddog_ins.global_position = pos1.global_position
pos1_taken = true
elif pos2_taken == false:
wooddog_ins.global_position = pos2.global_position
pos2_taken = true
elif pos3_taken == false:
wooddog_ins.global_position = pos3.global_position
pos3_taken = true
else:
wooddog_ins.global_position = pos4.global_position
pos4_taken = true
add_child(wooddog_ins)
# Here's my dead attempt at connecting the signal after 1000000th time of trying
wooddog_ins.connect("mouse_entered", _on_mouse_entered)
elif enemy == watersprite_PLOAD:
var watersprite_ins = watersprite_PLOAD.instantiate()
if pos1_taken == false:
watersprite_ins.global_position = pos1.global_position
pos1_taken = true
elif pos2_taken == false:
watersprite_ins.global_position = pos2.global_position
pos2_taken = true
elif pos3_taken == false:
watersprite_ins.global_position = pos3.global_position
pos3_taken = true
else:
watersprite_ins.global_position = pos4.global_position
pos4_taken = true
add_child(watersprite_ins)
elif enemy == mushroom_PLOAD:
var mushroom_ins = mushroom_PLOAD.instantiate()
if pos1_taken == false:
mushroom_ins.global_position = pos1.global_position
pos1_taken = true
elif pos2_taken == false:
mushroom_ins.global_position = pos2.global_position
pos2_taken = true
elif pos3_taken == false:
mushroom_ins.global_position = pos3.global_position
pos3_taken = true
else:
mushroom_ins.global_position = pos4.global_position
pos4_taken = true
add_child(mushroom_ins)
else:
var bikini_ins = bikini_PLOAD.instantiate()
if pos1_taken == false:
bikini_ins.global_position = pos1.global_position
pos1_taken = true
elif pos2_taken == false:
bikini_ins.global_position = pos2.global_position
pos2_taken = true
elif pos3_taken == false:
bikini_ins.global_position = pos3.global_position
pos3_taken = true
else:
bikini_ins.global_position = pos4.global_position
pos4_taken = true
add_child(bikini_ins)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
(I left a comment above the line where I tried to connect the signal)
What am I doing wrong?
I’ve watched tons of videos. I’ve looked in the godot docs. I’ve looked here…
…nothing