How to use area enter shape twice?

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

Hi, Im making a battle system in my game, and I want to make that depending on which part of the weapon hits the target area2d, it deals more damage. The signal area enter shape is not receiving the shape id correctly. The code is in the are itself.

var blade= self.get_shape(0)
var tip = self.get_shape(1)

The variables work correctly and contain the shapes as I want.

func _on_swordarea_area_enter_shape( area_id, area, area_shape, blade ):
    if area.is_in_group("enemy") :
	   print("damage")

The area reports the collision even when only the tip is colliding with the enemy area. Take in consideration that the two sword area collision shapes are not overlapping at any time, the two are separated.

I have two questions:
1.What Im doing wrong with the area_enter_shape() signal?
2.When the signal work how can I be able to use it differently later with the tip of the sword( change the self_shape parameter)?

Thanks in advance

:bust_in_silhouette: Reply From: unrealidiot

The signal comes from the Area2D node, not the shapes. You need two Area2D nodes so they generate separate signals.

This could have worked but I didn’t wanted to have to many area2d nodes. Thanks anyway

ArAdev | 2017-12-05 15:44

:bust_in_silhouette: Reply From: Michael Paul

Use _on_Area2D_input_event instead. Then create as many CollisionShape2D shapes as you need. On the event, just check the id to see what collided.

func _on_Area2D_input_event( viewport, event, shape_idx ):
  if shape_idx == 0:
     # tip collided
  if shape_idx == 1:
     # blade collided
  if shape_idx == 2:
     # hilt collided
     # etc..........

Thanks, at the end seeing this answer made me realize I was using the area_enter_shape() signal wrong, it worked using a similar structure to the one in the answer and it worked.

ArAdev | 2017-12-05 15:46

How does this work? I thought input event had to do with, well, input events.

unrealidiot | 2017-12-05 16:14

No, I mean that in the area_enter_shape() signal I was changing the parameter in the func statement and it didn’t work.
So instead of that I tried changing the self_shape inside the func, like this:

func _on_AreaEspada_area_enter_shape( area_id, area, area_shape, self_shape ):
         if self_shape==0:
                print("blade")
         if self_shape==1:
                print("tip")

and it just worked.

ArAdev | 2017-12-05 18:07