Hello! I should start off this post by saying that I am fairly new to Godot, but I have a good amount of coding experience and a little game dev experience. I'm currently trying to get a hitbox/hurtbox system working with Area3D objects attached to BoneAttachment3D's but the collisions are not registering. I've read through a good amount of documentation and tried for a couple days to debug it to no avail, so I decided to reach out for help.

The hitboxes are on collision mask layer 3 and the hurtboxes are on collision layer 3. Both the hurtboxes and hitboxes are scenes being instantiated at runtime through code, and have CollisionShape3D's as children of each of them. I currently have this code in my Hurtboxes:

extends Area3D

var material = load("res://Assets/Resources/hurtboxMaterial.tres")

func init(hurtbox):
	position.y += hurtbox.sizeY/2
	var boxSize = Vector3(hurtbox.sizeX,hurtbox.sizeY,hurtbox.sizeZ)
	var box : BoxShape3D = BoxShape3D.new()
	box.extents = boxSize/2
	$CollisionShape3D.shape = box
	var myMesh = MeshInstance3D.new()
	myMesh.mesh = BoxMesh.new()
	myMesh.mesh.set_size(boxSize)
	myMesh.mesh.surface_set_material(0, material)
	add_child(myMesh)
	self.area_entered.connect(_on_area_entered)

func _physics_process(delta):
	pass


func _on_area_entered(area):
	print("here")

("here" should get printed whenever a hitbox area enters the hurtbox. Init is called on the creation of a hurtbox. The hitboxes have similar code.)

And this is what my game currently looks like with my created debug mode on:

(Hitboxes/hurtboxes collide, but "here" isn't printed in console)

These CollisionShape3D's do appear in Godot's debugger as blue cornered boxes, but they are very hard to read so I created my own.

Am I not using the signal correctly? Am I misusing Area3D's? If I'm lacking in providing info, I'll add it in a reply. Any help would be appreciated.

  • xyz replied to this.
  • yukikon The hitboxes are on collision mask layer 3 and the hurtboxes are on collision layer 3.

    Shouldn't it be the other way around? If hurtbox is doing the detection its mask should be 3 (scans layer 3) and hitbox layer should be 3 (lives on layer 3)

    I don't know why the video didn't embed so I created a GIF instead, hopefully that embeds correctly

    yukikon The hitboxes are on collision mask layer 3 and the hurtboxes are on collision layer 3.

    Shouldn't it be the other way around? If hurtbox is doing the detection its mask should be 3 (scans layer 3) and hitbox layer should be 3 (lives on layer 3)

      xyz Oh my god, I can't believe I didn't even try that. Thank you so much.

      xyz Shouldn't it be the other way around?

      The order shouldn't matter. One object's collision layer and the other object's collision mask are bitwise and-ed, and if the result is nonzero, a collision is detected. Or is that not correct?

      • xyz replied to this.

        DaveTheCoder Nope. They're not just AND-ed. Layer is where a collider lives and mask is where it checks for collisions. The names are not very well chosen imho

        I just did a test (using Godot 3.5.2). I have a KinematicBody cube that moves toward a RigidBody sphere.

        If the cube has collision layer 1 and collision mask 2, and the sphere has collision layer 2 and collision mask 1, the objects collide.

        If the cube has collision layer 2 and collision mask 1, and the sphere has collision layer 1 and collision mask 2, the objects collide.

        • xyz replied to this.

          DaveTheCoder
          Sure. Your setup ensures that both objects detect one another because each is on the layer that coincides with other's mask.
          But if the cube has collision layer 1 and collision mask empty, and sphere has collision layer empty and collision mask 1, then sphere will report their collision and cube won't. If you swap it, then cube will report the collision and sphere won't. Try it out.

          Okay, I understand.

          But does "report their collision" matter to the physics engine? I.e., if only one of two colliding bodies reports a collision, does that affect movement?

          I can see that it would matter if you're using collision detection (via signals) for another reason.

          • xyz replied to this.

            DaveTheCoder But does "report their collision" matter to the physics engine? I.e., if only one of two colliding bodies reports a collision, does that affect movement?

            It's slightly different for dynamic bodies that run in the physics simulation. They don't emit collision signals by default afaik. If at least one of the bodies can detect the collision, the response in the simulation will happen. Otherwise it won't (they'll pass through). If only one is checking, there may be differences in the response depending on which one is checking, but both situations will cause a response.