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:
https://godotforums.org/uploads/editor/u5/rieg6wvxx4ej.png

Script for Hammer (player object):
https://godotforums.org/uploads/editor/cn/r2hqi7ywyjdy.png

Also here are the global variables/ autoload script but I don’t think they are affecting it.
https://godotforums.org/uploads/editor/rc/2hyqevbxg54z.png

: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():
anim.play(‘spawn’)
yield(anim, “animation_finished”)
isSpawned = true
anim.play(‘idle’)
timer.wait_time = duration
timer.start()

this function emits a signal to the Score node

changes animation then frees itself and flips isSpawned state

func _dizzy_mole():
emit_signal(“hasPoints”)
emit_signal(“loadMole”)
anim.play(‘dizzy’)
yield(anim, “animation_finished”)
anim.play(‘drop’)
yield(anim, “animation_finished”)
isSpawned = false
queue_free()

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
anim.play(‘hit’)
yield(anim,“animation_finished”)
_dizzy_mole()
else:
pass

registers if hammer is in the area, validating hits

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

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

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

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

func _on_Timer_timeout():
$CollisionShape2D.disabled
emit_signal(“loadMole”)
anim.play(‘drop’)
yield(anim,“animation_finished”)
queue_free()

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:
anim.play(‘idle’)
else:
pass

THE PLAYER OBJECT:

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”):
hammer.set_rotation(200)
emit_signal(“hammerTime”)
if Input.is_action_just_released(“ui_accept”):
hammer.set_rotation(0)