Checking Area2D without Collision?

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

Hello. Very new to this engine and need some help.

So I have 2 area2d’s for this simple whack-a-mole game that I am building.
My hammer is an Area2D and my moles are Area2D.
I have global variables in my AutoLoad for determining Hits and when Moles register as Hit.
The script is supposed to trigger an animation change and register a hit whenever the Area2D is entered by the hammer and when the “ui_accept” is pressed.
“Area entered” Signal is not executing like it should with the conditional.

My hammer is an Area2D with Sprite and CollisionShape2D as child nodes.
My mole is an Area2D with AnimatedSprite and C ollisionShape2D as child nodes.

I am using mouse-hover as control so obviously I don’t want the bodies to collide. I want the Area to be checked as the mouse hovers over them.

Not getting any error messages or the like and the debugger isn’t turning up anything obvious.

Script for Mole enemy:

Script for Hammer (player object):

Also here are the global variables/ autoload script but I don’t think they are affecting it.

:bust_in_silhouette: Reply From: SnapCracklins

Already solved it. I was referencing my global variables wrong.
They were messing up my signals.

The ENEMY object:

extends Area2D

ready sprite, timer, set a duration to adjust in editor

onready var anim = $AnimatedSprite
onready var timer = $Timer
export var duration = 2

bools to register hits and determine spawn status for animation control

var canHit = false
var isSpawned = false

signal emitted to current score to update total

signal hasPoints
signal loadMole

spawn animation on ready then spawn bool changes

timer begins for mole to “escape”

func _ready():‘spawn’)
yield(anim, “animation_finished”)
isSpawned = true‘idle’)
timer.wait_time = duration

this function emits a signal to the Score node

changes animation then frees itself and flips isSpawned state

func _dizzy_mole():
yield(anim, “animation_finished”)‘drop’)
yield(anim, “animation_finished”)
isSpawned = false

if hammer is in area and swung, this signal fires

if it is not in area, it passes

func _on_Hammer_hammerTime():
if canHit == true:
canHit = false‘hit’)

registers if hammer is in the area, validating hits

func _on_Moles_area_entered(area):
if == “Hammer”:
canHit = true

register if hammer is not in the area, not validating hits

func _on_Moles_area_exited(area):
if == “Hammer”:
canHit = false

“escape” function, hitbox deactivates, animation change, freed.

func _on_Timer_timeout():

function to switch from spawn to idle animation

waits for spawn animation to finish and reads bool to change animation

func _on_AnimatedSprite_animation_finished():
if isSpawned == true:‘idle’)


extends Area2D

export move speed, default vector, prep sprite and signal

export var speed = 1000
var vec = Vector2(0,0)
onready var hammer = $Sprite

this signal will call when the hammer swings

and the enemy will observe it

signal hammerTime

movement command code, per frame

func _process(delta):
# hard code mouse location for no stutter
self.position.x = get_global_mouse_position().x # set position to x of mouse
self.position.y = get_global_mouse_position().y # set position to y of mouse
vec = vec.normalized() * delta * speed # normalize it and multiply by time and speed
position += vec # move by that vector

# on accept button, swing the hammer, emit swing signal and then return

func _input(event):
if Input.is_action_just_pressed(“ui_accept”):
if Input.is_action_just_released(“ui_accept”):