First of all, Thanks for reading this and pardon me for my bad English
I'm a high school student who is new as a godot game developer, and my attempt is to create a top down 2D platform game like the game Bright Lancer (I will put the link if you wanna see https://slo-nod.itch.io/bright-lancer)
My problem begins in the attack, im trying to make a melee attack (the attack is not done yet) in the direction of the mouse. Unfortunately, my code cause debugs every time the player attack (which dont seem to be affect the functions) until you click the mouse button fast enough in order to stop the animation.
My apologize, maybe my code can give u a closer view:
var AttackPoints = 3;
var current_animation = "Idle"
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
To my way of thinking, the possible way this functions work, for instance, on the first attack of three, the function will play the animation (Attack) + "a" (a number based on the direction of the mouse), after play the animation, "a" will be null in order to lock the animation. After that, the idle animation will be played and "a" wont be null anymore.
Like I said, it will cause debugs "Attacknull not found" every time "a" == null, and if you click the mouse button fast enough, isplaying might still == true and "a" will be null for eternities, which will freeze the animation forever.
Hope my summary do help you, once again, thank you for reading my terrible question, I want to fix this as quick as possible and introduce the game for my friends so ask me if you guys need more information or other crazy things that you dont understand, I will definitely appreciate every small efforts you can made, and if you are too shy for that, here are some videos link that I used to write my code, hope it can help you guys something:
8 directions based on mouse direction:
https://www.youtube.com/watch?v=gEx_Fmf-MhU&t=107s
Melee attack:
https://www.youtube.com/watch?v=kxB_1DVlMkI
(it's 3am now so I might have some spelling mistake due to the sleepiness, just want you to know lol)