|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Bacon_Gb12 |
whenever i try to play the attack animation It only plays the first frame. how do i fix this?
if Input.is_action_just_pressed("Swipe"):
$AnimationPlayer.play("Attack")
I need more code to be sure, but you probably are playing another animation right after the attack animation starts since that only plays when the button is just pressed. You’ll need to disable that other animation when the attack animation is playing by checking a Boolean or something.
|
|
|
|
Reply From: |
magicalogic |
That is because the animation is played at the frame where the attack action is pressed. Try using Input. is_action_pressed(“attack”) instead to play the animation as long as attack is is pressed.
it still doesn’t work
Bacon_Gb12 | 2021-05-04 21:47
Maybe you should paste the whole script for us to figure out where the problem is.
magicalogic | 2021-05-05 05:49
extends KinematicBody2D
signal Health
var normal = true
const UP = Vector2(0, -1)
const GRAVITY = 20
const MAXFALLSPEED = 450
const MAXSPEED = 300
const JUMPFORCE = 400
const ACCEL = 10
var player_health = max_health
const max_health = 100
export var Damage = 1
var collision_damage = 50
var enemy_damage = 100
var facing_right = true
var motion = Vector2()
func _ready() → void:
pass
func _physics_process(_delta):
if player_health == 0:
Kill()
if Input.is_action_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")
if motion.y == 450:
$AnimationPlayer.play("Fall")
func Kill():
get_tree().reload_current_scene()
func _on_Area2D2_area_entered(_area: Area2D) → void:
print(“Ouch!”)
player_health -= 10
print(player_health)
emit_signal(“Health”, player_health)
Bacon_Gb12 | 2021-05-05 11:01
Before playing the walk and idle animations, do an if statement, checking if the player is not doing the attack animation.
if Input.is_action_pressed("right"):
motion.x += ACCEL
facing_right = true
if !$AnimationPlayer.get_current_animation("Attack"):
$AnimationPlayer.play("Walk")
elif Input.is_action_pressed("left"):
motion.x -= ACCEL
facing_right = false
if !$AnimationPlayer.get_current_animation("Attack"):
$AnimationPlayer.play("Walk")
else:
motion.x = lerp(motion.x,0,0.2)
if !$AnimationPlayer.get_current_animation("Attack"):
$AnimationPlayer.play("Idle")
or copy/paste this bad boy^
dari0us | 2021-05-06 17:45