@TwistedTwigleg said:
If you just want to know whether nothing is in the Area, then using code similar to what you have would work. You could potentially save a touch of performance by checking the size rather than comparing to an empty array:
if ($hitBox.get_overlapping_areas().size() == 0):
print ("null")
else:
print ($hitBox.get_overlapping_areas())
If you want to check if a specific Area is not inside the Area, then you could do something like this:
var overlap_areas = $hitBox.get_overlapping_areas()
var avoid_node_in_area = false
for area in overlapping_areas:
if area == $NodeToAvoid:
avoid_node_in_area = true
break
if (avoid_node_in_area):
print ("The avoid node is inside!")
else:
print ("The avoid node is not inside")
However this involves going through the entire array every time. Instead, you can use a combination of the area_entered
and area_exited
functions to speed things up a bit so you do not need to iterate over the entire array each time:
var avoid_nodes_in_area = []
func _ready():
connect($hitBox, "area_entered", "on_area_entered")
connect($hitBox, "area_exited", "on_area_exited")
func _process(_delta):
if (avoid_nodes_in_area.size() > 0):
print ("Avoid node(s) in Area!")
else:
print ("No avoid node(s) in Area!")
func on_area_entered(area):
if area == $NodeToAvoid:
avoid_nodes_in_area.append(area)
func on_area_exited(area):
var find_index = avoid_nodes_in_area.find(area)
if (find_index != -1):
avoid_nodes_in_area.remove(find_index)
I dont know if it will work... iam toggling the area.collision to enable or disable, in the animation and frame.
hitBox = get_node("hitBox/CollisionShape");
if frame == 1 : hitBox.disabled = false; else: hitBox.disabled = true;
Ive noticed that with very high speed in the animation, the get_overlapping_areas() could not detect anything and the player would not perform a combo ( attack chain 1, 1, 2, 3, 4...attacks ) because the hit would always return false.
Iam using the code in the area.tscn ( hitbox ) on the player tree.
func _ready():
attacker = get_owner();
victim = 0;
pass
func _on_hitBox_area_entered(area: Area) -> void:
victim = area.get_owner();
#---set--victim----
victim.state = "st_pain1";
victim.d_frame = 0;
victim.anim.frame = 0;
victim.anim.play("pain1");
victim.frameTimer = 1;
victim.pauseTimer = hitPauseTime;
#---set--attacker----
attacker.didHit = true;
attacker.comboDelay = 0.7;
attacker.combo += 1;
attacker.pauseTimer = hitPauseTime;
The problem here is in the pauseTimer's.
It exits (return) the physics process on both player and enemy.
So they can both get a hitPause effect when an attack connects.
If i dont changed them both at the same time togheter with all those variables, i will get 1 clicle of delay in the code...
basically this happens - player connects the attack on frame 1 ( pauses )... enemy ( pauses ) on idle, then afteer pause goes into "pain" state and plays animation pain.