0

i have a player character that has 2 attack types, a single punch and a combo attack. i want it that when the player is not near any objects/ or enemy AI to play the single punch. and if the player is in attacking distance , to play the combo attack.

the problem is that I dont know how to switch the attacks since they are both bound to the 'J' key. ive tried to change the attack when the player is in the objects 'body_entered_area' but it doesnt work.

I cant find any tutorials either online . thanks

i setup a basic player move and attack script and then added a function with combo . then i tried to initialise the combo when the player enters the enemys area body . but without success

1 Answers1

0

Firstly i would try to print signal which changed when body_entered_area - adding some, var for example:

var close_to_enemy

which changed when body is entered and body_exited_area:

 func body_entered_area():
     close_to_enemy = true
     print("close_to_enemy")


 func body_exited_area():
      close_to_enemy = false
      print("far_from_enemy")

That print could you help navigate on console if this is working or not.

After that you can add that var (which we created) in to your animation/key trigger/etc. to changed that action depends on that var.

  • thank you for your response. to confirm the player does register its presence when near the enemy collision. however I think the issue is that since the combo attack is physics based the collision detection code needs to also be in the _physics_process. I'm looking at various different methods of triggering the combo Ie using 'ovelapping bodies'. the problem seems to be that the combo doesn't trigger because it's in the 'func body_entered' parameter and not in the physics process. honestly, it's all too much for me . I'm still learning coding. thank you anyway – Christopher Ciftci Apr 07 '23 at 07:37
  • just wanted to add a late response again to your answer. I now comprehend the meaning regarding your answer and kind of figured it out . due to my lack of experience in coding I failed to understand your answer but I greatly appreciate that you did answer my question .thank you – Christopher Ciftci Apr 25 '23 at 16:44
  • It is okay. I stuck in coding many times. In my case is just - patience. Many times is all about learning small things which evolve in something bigger. You can give up. It is okay. But If you decide to try again - you will be definitely closer to the solution... – Atelier Morph Art - Voleybot Apr 27 '23 at 18:15