Не работает анимация атаки. проигрывается только на мгновение. посмотрел много гайдов и почитал кучу сайтов. не помогает

extends CharacterBody2D

const SPEED = 50.0
const JUMP_VELOCITY = -300.0
@onready var anim = $Animated
var health = 100
var money = 0
var mana = 200
var magic_arrow = preload(“res://обьекты/Обьекты/magic_arrow.tscn”)
var magic_ligh = preload(“res://обьекты/Обьекты/magic_lightning.tscn”)
var magical = true
var state = false

func _physics_process(delta: float) → void:

if not is_on_floor():
	velocity += get_gravity() * delta

if Input.is_action_just_pressed("ui_accept"):
	velocity.y = JUMP_VELOCITY
	anim.play("Jump")

var direction := Input.get_axis("Left_Walk","Right_Walk" )
if direction:
	velocity.x = direction * SPEED
	if velocity.y == 0:
		anim.play("Walk")

else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	if velocity.y == 0 and state == false:
			anim.play("Idle")

if Input.is_action_just_pressed("Magic1"):
	state == true
	magic1()

if Input.is_action_just_pressed("Magic2"):
	magic2()

if direction == -1:
	$Animated.flip_h = true
	
elif direction == 1:
	$Animated.flip_h = false

$MagicAttack1.look_at(get_global_mouse_position())

if health <= 0:
	queue_free()
	get_tree().change_scene_to_file("res://Сцены/menu.tscn")
	
move_and_slide()

func magical():
if mana == 0:
magical = false

func magic1():
if magical == true and is_on_floor():
anim.play(“Attack”)
await anim.animation_finished
var b = magic_arrow.instantiate()
owner.add_child(b)
b.transform = $MagicAttack1/Marker.global_transform
mana -= 10
state == false

func magic2():
if magical == true and is_on_floor():
anim.play(“Attack2”)
var r = magic_ligh.instantiate()
owner.add_child(r)
r.transform = $MagicAttack1/Marker.global_transform
mana -= 50

func _on_timer_timeout() → void:
if mana < 200:
mana += 1

This is not a type of “forum feedback”, change the tag to “help” category, change the language of the title to english and explain your problem as much.

1 Like

Can’t test right now, but this:

state == true

probably doesn’t do what you expect it to. This tests whether state equals true instead of true to state. When _physics_process is called again, this line:

	if velocity.y == 0 and state == false:
			anim.play("Idle")

Will set the animation back to the idle animation.

Is that the problem you’re facing?