Area2D collision

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serenade
:warning: Old Version Published before Godot 3 was released.

Hey!
Im trying to make object that shoots objects and when it hits a player object, it should disappear.
I want to make the bullet disappear when ever it hits something, but the problem is, if i make it to recognise Area2D and disappear, it works, but at the same time, it doesnt do that for collisionshape2d… and when i add: if_is_colliding():queue_free() … but then, Area2D doesnt get signal (and i got attached code for area2d, that when obj enters area, subtract HP…) also, if i use enter_body signal, instead of enter_area, the bullet obj disappears when created. (im also using separate scenes in one scene.)
So, how you can add exception for self in area_body or maybe you have an easy project that has simple shooting, receiving damage project to share…?
I hope you understand what i meant,lol

I usually make the object detecting collision call a function on the other, so they both know what happened and only one needs to monitor collisions. But that’s my way^^

In the official 2D platformer demo, the character is able to shoot enemies with bullets. Maybe you can have a look at it?

Zylann | 2017-01-26 13:49

Im trying to do that, but it doesnt work, also i cant a make a area to detect collission from another scene (object like an enemy) groups dont work across the scenes too : /
I have looked at those, but that is in Rigidbody and that whole code is just too complex for me (im rly a beginner) all those extend and such, i dont know those and those tutorials just dont seem to make any sense to me : /

Serenade | 2017-01-26 14:01

The shooter demo could be the most simple one to look at.


Groups should work between scenes, maybe you need to update or re-add the instanced scenes if you added the groups later.

eons | 2017-01-26 15:35

:bust_in_silhouette: Reply From: mateusak

I’m not sure I understood it* but you can just use:

func body_enter(body):
   if body == self:
      return

   #code

*You NEED to use code sample “is_colliding()”, otherwise everything is emphasized, because someone thought making _ the symbol for that was a good idea.