How to set Area2D monitorable to true while inside an area?

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

I wanted to make a simple player fighting mechanic, so i set a simple code

	onready var sword_hitbox = $Hitbox_pivot/Hitbox
if Input.is_action_pressed("attack"):
	sword_hitbox.monitorable = true
	sword_hitbox.monitorable = false

The problem is that when my “sword hitbox area” is already in the “enemy hurtbox area”, the monitorable is still false even when i press attack. So i have to exit the “hurtbox area” and press the attack button, and enter the “hurtbox area” to let the “hurtbox” detect my sword hitbox area. and its annoying.

note: when i press attack button, the hitbox is set to monitorable so that it can be detected to let the enemy take damage

But i wanted let the "enemy hurtbox area to detect the “hitbox area” even when its already in the “hurbox area”

:bust_in_silhouette: Reply From: Inces

So You are saying area collision is not triggered when set monitorable to true while already in collision. You can use collision_shape.disabled instead. You can use set_collision_mask instead. You can set scale of collision shape from 0 to base. At least one of these must be triggered when already overlapping another area :slight_smile:

Alternatively You can get collisions without the signal :

if Input.is_action_pressed("attack"):
         for area in sword_hitbox.get_overlapping_areas():

I found out you can easily use the disabled property, but thanks Inches for helping!

if Input.is_action_pressed("attack"):
	$HitboxPivot/Hitbox/CollisionShape2D.disabled = false
	$HitboxPivot/Hitbox/CollisionShape2D.disabled = true

condair | 2022-03-03 01:47