0 votes

I want to make melee attack like this game https://slo-nod.itch.io/bright-lancer which will trigger everytime you click the mouse button. Beside that, my code is following to this https://www.youtube.com/watch?v=gEx_Fmf-MhU&t=107s, a tutorial about playing 8 direction animations with the mouse, of course. I try to combine it with melee attack but seem like they aren't doing well, debugs show up everytime and thus, whenever u attack too much, the function will be null and stop playing animation, here is the code for more closer view:

var AttackPoints = 3;

var s = 0
var i = 0
var a = 0
var b = 0
var c = 0

func _process(delta:float):
   if isplaying == false:
    var mouse = get_local_mouse_position()
    s = stepify(mouse.angle(), PI/4) / (PI/4)
    s = wrapi(int(s), 0, 8)

    if Input.is_action_just_pressed("skill"):
        i = s

    if Input.is_action_just_pressed("attack"):
        a = s
        b = s
        c = s

func move_state(delta:float):
   if Input.is_action_just_pressed("attack") and AttackPoints == 3:
    $AttackResetTimer.start();
    state = ATTACK;
    AttackPoints = AttackPoints - 1;

  elif Input.is_action_just_pressed("attack") and AttackPoints == 2:
    $AttackResetTimer.start();
    state = ATTACK2;
    AttackPoints = AttackPoints - 1;

  elif Input.is_action_just_pressed("attack") and AttackPoints == 1:
    $Attack3ResetTimer.start();
    state = ATTACK3;
    AttackPoints = AttackPoints - 1;

func attack_state() -> void:
  isplaying = false;
  animationTree.active = false;
  animationPlayer.playback_active = true;
  current_animation = "Attack";
  animationPlayer.play(current_animation + str(a));
  animationPlayer.playback_speed = 1.75;
  isplaying = true;

 if isplaying == true:
    a = null

func attack2_state() -> void:
 $Sprite.visible = false
 $Sprite2.visible = true
 isplaying = false
 animationTree.active = false
 animationPlayer.playback_active = true
 current_animation = "AttackTwo"
 animationPlayer.play(current_animation + str(b))
 animationPlayer.playback_speed = 1.75
 isplaying = true

 if isplaying == true:
    b = null

func attack3_state() -> void:
 $Sprite.visible = false
 $Sprite2.visible = true
 isplaying = false
 animationTree.active = false
 animationPlayer.playback_active = true
 current_animation = "AttackThree"
 animationPlayer.play(current_animation + str(c))
 animationPlayer.playback_speed = 1.75
 isplaying = true

 if isplaying == true:
    c = null

func attack_animation_finished()->void:
if state == ATTACK || state == ATTACK2 || state == ATTACK3:
    $Sprite.visible = true
    $Sprite2.visible = false
    isplaying = false
    current_animation = "Idle"
    animationPlayer.play(current_animation + str(s))
    isstop = false
    state = MOVE

    if isstop == false:
        s = null

I want to fix this as quick as possible, so ask me if you guys need more information (big thanks for the help)

Godot version godot 3.3
in Engine by (54 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.