Damage signal

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

if i want to send a signal telling to damage whatever is in the area2d how would i do it in the player script or the enemy script

:bust_in_silhouette: Reply From: eons

When A enters damage area of B, the area belongs to B and it can do something with the area_enter (basically, process the signal).

There, B will get a reference to A and can directly do A.damage(value) (after checking that can do that to A, looking for groups, types, etc.).

A will decide what to do with damage().

So what your saying is the one that will have the damage code, if A attacked B, will be B

Newby | 2017-10-26 10:42

You can make that the entity that does the damage, applies it, but is usually better to let each entity manages their own properties using a common interface (in this case, damage()).

The flow is:
Attacker attacks
->Area detects a body
->Area notifies the attacker (signaled)
->Attacker validates the body
->Attacker “tells” the body about the action (body.damage(value, etc))
->Body executes its damage() function logic.

eons | 2017-10-27 00:14