The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

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 (58 points)

1 Answer

0 votes

Giving us the debug message would've helped, too. Which function returns null? stepify, wrap, move_state? Which function(s) stop working if you attack too much?

One thing I noticed from your code is that AttackPoints never resets back to 3. I don't know if you left that piece out of this code or if you really forgot about it. It looks like it should go into the attack_animation_finished() function.

Another thing that doesn't make much sense is the a b c. From the looks of it, you could've used s on all 3 attack states without any problem or difference, unless the attacks queue up, each with their own direction.

isplaying is set to false, then true shortly afterwards, without any apparent check or use in between. Why? Also, why check if it's true when you literally set it to true on the line above it? (Protip, when dealing with boolean variables, if varname: works better than if varname == true)

by (294 points)

First of all, from the bottom of my heart, I'm so sorry that my question does giving you the annoying that you don't deserve, I haven't really gave any effort for this one, I have made another question already, which I hope can satisfy all of your suggestions.

Of course, if you don't might, I will put the link here:
https://godotengine.org/qa/119680/how-can-i-create-melee-attack-based-on-mouse-direction

(you are under no obligation to answer my question again, but of course, if you do, I will really appreciate)

Once again, I'm really sorry that my question had giving you an unpleasant experience that you don't want and further more, my bad English too.

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 Frequently asked questions and 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 [email protected] with your username.