The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

So I have done this enter image description here

In my project the same kinematic body can be used by player and enemy. When the punchhit area 2d collides with Hurtbox area 2d a hurt animation plays. I want the Hurtbox to ignore this when it's own punchhit is colliding.

Any ideas aside from adding new groups to the Area_2Ds?

Godot version 3.2.3
in Engine by (208 points)

4 Answers

+1 vote
Best answer

You could check it manually. In the code run when the two areas collide, verify if it is the sibling Node.
Edit, if you have a script in Hurt_Box :
onready var own_punch = $"../Punch Hit" #".." represents the parent Node.
func on_Hurt_Box_area_entered(area):
. if area != own_punch: #don't punch yourself
. . pass #all good, you can punch

Alternatively, if enemies can only hurt players, and vice versa, you can use collision masks. punch_player collides with hurt_enemy, and punch_enemy collides with hurt_player.

by (2,720 points)
selected by
+1 vote

I would recommend reading this:

Layers and masks are not I tried before my own projects but I think this is your solution.

by (20 points)

Thank you I will look at this. I'm sure it will help.

+1 vote

Set up the physics layer, and assign it in the editor it should automatically work.

The Docs has a set by step for a the basic set-up it should work.

by (50 points)

Thanks. I will check it out. I was trying to make it so that any character can hurt any character like in Grand Theft Auto or Skyrim.
I'm using a script to assign ID to every generated NPC and that ID gets added as a group to the character's collision so when the punch collides with the character's own collision shape it checks if the ID is the same as it's own and returns the function.

0 votes

I'm answering the solution that works for me.

I wanted to make it like GTA or Skyrim where anyone can attack anyone. I just wanted the collision shape to not get triggered by their own punches.

Giving every character unique generated IDs works. After the ID is generated. Use var2str and add the area2d to the group var2str(ID). When area enter is being checked make sure your area doesn't belong in var2str(This character's ID).

by (208 points)
reshown by
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 Frequently asked questions and 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 [email protected] with your username.