I wrote when for animation you can leave the game file in the message and you will open in your Godot Engine , it and look at the code and animations, because if I leave my entire script then it will be a lot and the animations cannot be fixed by simply correcting the code (in my opinion). And so I wrote the code for a super attack, that is, if you press the attack button while playing the attack animation at a certain time, there will be another animation that is understood as a super attack.
Sorry, but I completely don’t understand your message.
Do you mean you want to know how to check the animation’s timing to trigger a super attack, or is it about debugging the way the animation and code interact?
Please try to explain again. If you have troubles formulating the question in English - maybe try asking ChatGPT to formulate the question for you and post it here.
I wrote a script so that during the attack animation on a certain frame you can press a button and the animation of another attack, which is understood as a super attack, will start. But this code does not work, when I press the button on a certain frame nothing happens
can you share your code?
Share your code here then
extends CharacterBody2D
enum {
MOVE,
ATACK,
ATACK2,
ATACK3,
SLIDE,
BLOCK,
}
const SPEED = 150.0
const JUMP_VELOCITY = -400.0
var state = MOVE
var runSpeed = 1
@onready var anim = $AnimatedSprite2D
@onready var animPlayer = $AnimationPlayer
var health = 100
var gold = 0
var combo = false
func _physics_process(delta: float) -> void:
match state:
MOVE:
move_state()
ATACK:
atack_state()
ATACK2:
atack2_state()
ATACK3:
pass
BLOCK:
block_state()
SLIDE:
slide_state()
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
if velocity.y > 0:
animPlayer.play("fall")
if health <= 0:
health = 0
animPlayer.play("death")
await animPlayer.animation_finished
queue_free
get_tree().change_scene_to_file("res://menu.tscn")
move_and_slide()
func move_state():
var direction := Input.get_axis("ui_a", "ui_d")
if direction:
velocity.x = direction * SPEED *runSpeed
if velocity.y == 0:
if runSpeed == 0.5:
animPlayer.play("walk")
else:
animPlayer.play("run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y == 0:
animPlayer.play("Idol")
if direction == -1:
anim.flip_h = true
elif direction == 1:
anim.flip_h = false
if Input.is_action_pressed("run"):
runSpeed = 2
else :
runSpeed = 0.5
if Input.is_action_pressed("block"):
if velocity.x == 0:
state = BLOCK
else :
state = SLIDE
if Input.is_action_just_pressed("atack"):
state = ATACK
func block_state():
velocity.x = 0
animPlayer.play("block")
if Input.is_action_just_released("block"):
state = MOVE
func slide_state():
animPlayer.play("slide")
await animPlayer.animation_finished
state = MOVE
func atack_state():
if Input.is_action_just_pressed("atack")and combo == true:
state = ATACK2
velocity.x = 0
animPlayer.play("atack")
await animPlayer.animation_finished
state = MOVE
func atack2_state():
animPlayer.play("atack2")
state = MOVE
func combo1 ():
combo = true
await animPlayer.animation_finished
combo = false
Here, you are checking if combo == true
.
func atack_state():
if Input.is_action_just_pressed("atack")and combo == true:
state = ATACK2
You are assigning combo = true
only within the combo1()
method here
func combo1 ():
combo = true
But I don’t see this combo1()
method being called anywhere within your code (at least in this script, maybe it’s called from outside of this script?). Therefore, combo
will never be true
, so your code will never propagate to state = ATACK2
.
Make sure to call the combo1()
method somewhere.
thanks , I’ll double check now
I don’t quite understand how to fix this, can you give me some code or more details, but I found the only place where this seems to be called
Try adding some print()
statements in your code to understand what happens in each of the situations and debug the issue.
I added print()
, but nothing appeared in the console, only new lines.
I added it after func atack_state():
Tell me where it is better to put it to find the problem
put a print statement in the combo-method:
func combo1():
print("Can combo!")
combo = true
and change your atack2_state:
func atack2_state():
animPlayer.play("atack2")
await animPlayer.animation_finished
state = MOVE
Thank you, you helped me, but could you please describe in more detail what the error was, I am just a beginner game developer and want to gain experience in this field
Well the only thing that changed was the “await animPlayer.animation_finished”. You forgot to wait until the attack2 is over to go back to the move-state. You did it correctly for attack1 but just forgot about it in attack2