![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | owlisGODOT |
I’m following a tutorial and I want to add a feature myself where you can slash the enemy. So far I’m working on the animation (called “Attack 1”), though I have a problem.
It only plays the first frame, then just switches to the idle animation. For some reason the other animations work fine, so I don’t understand what’s wrong. How do I get it to play the rest of the animation???
(for reference here’s the player script)
extends KinematicBody2D
const FLOOR = Vector2(0, -1)
const GRAVITY = 30
const JUMP_HEIGHT = -800
const SPEED = 300
const FIREBALL = preload("res://fireball.tscn")
var vel = Vector2()
var ground = false
func _physics_process(delta):
if Input.is_action_pressed("ui_left"):
vel.x = -SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = true
if sign($Position2D.position.x) == 1:
$Position2D.position.x *= -1
elif Input.is_action_pressed("ui_right"):
vel.x = SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = false
if sign($Position2D.position.x) == -1:
$Position2D.position.x *= -1
else:
vel.x = 0
if ground == true:
$AnimatedSprite.play("Idle")
if Input.is_action_pressed("ui_up"):
if ground == true:
vel.y = JUMP_HEIGHT
ground = false
vel.y += GRAVITY
if Input.is_action_just_pressed("shoot"):
var fireball = FIREBALL.instance()
if sign($Position2D.position.x) == 1:
fireball.set_pos(1)
else:
fireball.set_pos(-1)
get_parent().add_child(fireball)
fireball.position = $Position2D.global_position
if Input.is_action_just_pressed("slash"):
$AnimatedSprite.play("Attack 1") # <---- Bug
else:
$AnimatedSprite.play("Idle")
if is_on_floor():
ground = true
else:
ground = false
if vel.y < 0:
$AnimatedSprite.play("Jump")
else:
$AnimatedSprite.play("Fall")
vel = move_and_slide(vel, FLOOR)
(I apologize for the improper indentation, it was hard to manually indent everything X( )
To properly paste code in the forum.
- copy properly formatted code from your text editor
- paste it into the forum message
- select it
- Press the
{}
button in the forum message toolbar
That’ll indent everything properly for forum display…
jgodfrey | 2020-06-09 15:50