Collisionpolygon2D(child of area2D) does not "hit" the "hurtbox" which is an area2D

Godot Version 4

4.4

Question

I have a CollisionPolygon2D inside an Area2D that should "hit" with another Aread2D but the "hurtbox" is not detecting the "hitbox" or viceversa?

THE CODE FOR THE ITEM THAT IS BEING HIT:

extends Node2D
var grassEffect = load(“res://Effects/grass_effect.tscn”)

func create_grass_effect():
var grassEffectInst = grassEffect.instantiate()
var world = get_tree().current_scene
world.add_child(grassEffectInst)
grassEffectInst.global_position = global_position

func _on_hurt_box_area_entered(_area):
print(“yes”)
create_grass_effect()
queue_free()

I added as many signals as possible but it still didn’t work. Except with body_entered which used the collisionshape of the character instead of the sword.

HERE IS THE CODE OF THE GRASSEFFECT:

extends Node2D
@onready var animatedSprite = $AnimatedSprite2D

func _ready():
animatedSprite.frame = 0
animatedSprite.play(“grassCut”)

func _on_animated_sprite_2d_animation_finished() → void:
queue_free()

I am following a tutorial that is very old and as I do that I learn by somewhat “updating” the code.

This is the tutorial: [https://www.youtube.com/watch?v=vDbEfmPcv-Q&list=PL9FzW-m48fn2SlrW0KoLT4n5egNdX-W9a&index=12](tutorial RPG action in godot)

I will post a short video of what I did with the collisionpolgon2d
I CANT UPLOAD ATTACHMENTS T_T

There’s a lot of reasons that collisions don’t work, I made a list here.

But maybe one reason is that your collision polygon is disabled?

I have checked and it is disabled. I am using an area node, saving it as a scene and then adding that to a CharacterBody2D. The area2D has a child which is a CollisionPolygon2D.

I have checked from your list and there are a few things that I believe might be the issue. Tried some but I will try others later. So far, I think it is related to the complexity of the shape (I don’t think it is way too complex) or the topic related to concave or convex other polygons. I did ALT + TAB a few times before and it got the hit-box to work back when it was always “enabled”.

UPDATE!

I deleted it and started again. So far I have only created a very simple shape with 5 axes. Before I keyd the polygon and other elements in the animationPlayer node but right now I am not doing so. I have only keyd the disable element of the collisionPolygon2D and it is KIND OF working.

I had to key the colisionPolygon2D as disabled on all the other animations (IDLE and RUN - up - down - left - right). The weird part is that all attack sides are working but I only disabled enabled the polygon for attack-down and not all other sides.

Extra Info:

This is how I build the character that is hitting: I created a new scene where the main node was an area2D node with a collisionPolygon2D as a child. I then saved it as a scene and then brought it to a characterbody2D to be used as a hitbox.

The characterBody2D was also saved as a scene with different children like sprite and animationPlayer and animationTree.

This is how I created the hurting: built a scene with a sprite as a child and the “hurtbox” scene I had already created. The hurtbox scene is made of a parent as AREA2D and a child as collisionpolygon2D.

UPDATE

I notice that if I key the “Polygon” shape in every frame, meaning change the shape of the polygon at every frame, then GODOT 4.4 just doesn’t detect it going going into the “Hurtbox” Area2D

Is this normal?

Yeah I had the same problem with a teleporter, I think if you delete the scene (if you can) and then create it again it might work!

1 Like

UPDATE

I tried creating a different CollisionPolygon2D NODE for every different frame and that KIND OF WORKED, but the CollisionPolygon2D is not enabling and disabling correctly. I had to write some code to disable the CollisionPolygon2D when _ready and all the CollisionPolygon2D shapes are enabling as soon as the animation starts instead of frame by frame.

I will follow @pro_core3 advice next time. I will add the node directly instead of saving it as an scene and then adding it.