0 votes

Hi, I'm making a zeldalike where you can walk around, get hit by enemies, and hit them back with a sword. I have an enemy (a bee) that has a sight box, a circle around it so it can detect the player and start moving towards him.

The issue is that this sight box "hits" the player, causing him to take damage.

The sight box has no layer, and its mask it set to only see the player. The player's hurtbox is set on the player layer, and its mask is set to only see enemies.

My understanding is that this setup would cause the hurtbox to never register the sight box, because the sight box has no layer. But of course, the sight box would see the player, because its mask is set to look for the player.

Can anyone tell me what I'm doing wrong, or how I'm misunderstanding the system? It seems like what's happening is that if a collision is registered in one direction (i.e. the sightbox registering the player) somehow that necessitates the collision registering in the other direction (the hurtbox registering the sight box)? Is that what's happening? And if so, that seems counterintuitive to say the least. How should I get past this?

Thanks very much.

Godot version 3.3.1
in Engine by (34 points)

Please post some more code :) would be helpful to know how you connected your signals, and where the function that applies damage to the player is happening. Also, are you using area2D? Or physics bodies?

What you're trying to do should be possible and fairly simple. Likely just a little mistake somewhere

func _on_hurtbox_area_entered(area):
get_hit()

func get_hit():
deplete_pod()
emit_signal("on_grip_changed", current_pod_fill)

I guess I should explain a little more, yeah :) the game actually takes place on a climbing wall, so the player has grip rather than health. There is a 'grip' node which has the above code on it, which it receives as a signal from the player's hurtbox. As mentioned above, the hurtbox is what has its layer as player and the mask as enemy. So far it is done through Area2Ds rather than bodies.

So my understanding is that the hurtbox, in only being able to sense areas of type enemy through its mask, would not see the sight box, because the sight box has no layer- by my understanding the sight box itself should be essentially invisible to everything else. Is this accurate, or have I misunderstood something?

2 Answers

0 votes

Is the bee sending out a signal which the player character is listening for and causes damage? difficult to say for sure without code but that seems plausible.

by (1,635 points)
+1 vote

So, area2D has 4 properties that are relevant here:
Monitoring and monitorable, which control whether it is listening for overlaps and whether it can be "heard"

And then there's layer and mask.
Layer controls which collision groups this object is part of
Mask controls which layers this object is looking at for collisions

So if your bee area is on layer one, and and there's any other objects on that layer too, then they will also trigger area entered events.

For debugging purposes I would print(area.get_path()) to see who's triggering your area entered event and check their collision layers and mask. Also worth checking to make sure that you're not reusing the same script on a second object by accident. And that there's no other signals connected to you area entered function

by (1,260 points)

Well thank you, I was able to find out that it is for sure the bee's sight box that was being noticed by the player's hurtbox, despite the fact that the sight box was on no layers whatsoever and shouldn't even be able to trigger anything (as I understand it).

There was for sure something wonky going on, but I couldn't figure it out. I ended up 'solving' it by making a new seeable layer and having the bee's sight box look for bodies of that type, and then putting the player's kinematicbody2D layer as seeable.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.