inputkeypressswitching

changing attack types / states which are bound to same key input in godot


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


Solution

  • 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.