Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | WimpyBaby |
I’m currently learning basic 2d platformer movement and animation, where the player can use sword attacks to hit enemies. Animation for idle:ing, running, jumping and falling have all been working except the attack animation.
func _physics_process(delta):
motion.y += get_gravity() * delta
if Input.is_action_pressed("ui_right"):
motion.x = min(motion.x+ACCELERATION, max_speed)
elif Input.is_action_pressed("ui_left"):
motion.x = max(motion.x-ACCELERATION, -max_speed)
else:
motion.x = lerp(int(motion.x), 0, 0.2)
if is_on_floor():
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_VELOCITY
if isAttacking == false and Input.is_action_just_pressed("Attack1"):
isAttacking == true
print("attack true")
motion = move_and_slide(motion, UP)
Animation_player(motion)
print(motion)
pass
func Animation_player(motion):
if motion.y < 0 and isAttacking == false:
$AnimatedSprite.play("Jump")
if Input.is_action_pressed("ui_left"):
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("Jump")
if Input.is_action_pressed("ui_right"):
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("Jump")
elif motion.y > 0:
$AnimatedSprite.play("Fall")
elif motion.x > 0 and isAttacking == false:
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("Run")
elif motion.x < 0 and isAttacking == false:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("Run")
else:
$AnimatedSprite.play("Idle")
func attack():
if isAttacking == true:
$AnimatedSprite.play("Attack")
I’ve tried implementing the attack animation into the animation player function but that only causes the other animations to stop functioning.