![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Bacon_Gb12 |
im trying to make an attack animation and i wrote this:
if Input.is_action_just_pressed("Attack"):
$AnimationPlayer.play("Attack")
It doesn’t work for some reason, can someone help?
It can be many reasons. Please provide more information.
avnih | 2021-04-24 18:06
what info do you need?
Bacon_Gb12 | 2021-04-24 18:25
whenever I press attack it resets the idle animation and i don’t get any errors
Bacon_Gb12 | 2021-04-24 18:26
I’m guessing that it plays for one frame and then goes back to the idle animation. Can we see the rest of your code?
exuin | 2021-04-24 20:11
xtends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 20
const MAXFALLSPEED = 300
const MAXSPEED = 300
const JUMPFORCE = 400
const ACCEL = 10
var facing_right = true
var motion = Vector2()
func _ready() → void:
pass
func _physics_process(_delta):
if Health <= 0:
Kill()
if Input.is_action_just_pressed("Swipe"):
$AnimationPlayer.play("Attack")
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
if facing_right == false:
$Sprite.flip_h = true
else:
$Sprite.flip_h = false
motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED)
if Input.is_action_pressed("right"):
motion.x += ACCEL
facing_right = true
$AnimationPlayer.play("Walk")
elif Input.is_action_pressed("left"):
motion.x -= ACCEL
facing_right = false
$AnimationPlayer.play("Walk")
else:
motion.x = lerp(motion.x,0,0.2)
$AnimationPlayer.play("Idle")
if is_on_floor():
if Input.is_action_just_pressed("jump"):
motion.y = -JUMPFORCE
motion = move_and_slide(motion,UP)
if Input.is_action_just_pressed("Attack"):
$AnimationPlayer.play("Attack")
var Health = max_health
var attack_cooldown_time = 1000
var next_attack_time = 0
var attack_damage = 30
const max_health = 100
export var Damage = 1
var collision_damage = 50
var enemy_damage = 100
func Kill():
get_tree().reload_current_scene()
func _on_Area2D_area_entered(_area: Area2D) → void:
print(“Ouch!”)
$AudioStreamPlayer.play()
Health -= 10
print(Health)
Bacon_Gb12 | 2021-04-24 20:46