Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LifeRips |
My character freezes when “Attack” is pressed. After this, I can only jump in place with ui_up. Here is my code:
extends KinematicBody2D
const SPEED = 100
const GRAVITY = 10
const JUMP_POWER = -250
const FLOOR = Vector2(0, -1)
var isAttacking = false
var velocity = Vector2()
var on_ground = true
func _physics_process(_delta:float) → void:
if Input.is_action_pressed("ui_left") && isAttacking == false:
velocity.x = -SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = true
elif Input.is_action_pressed("ui_right") && isAttacking == false :
velocity.x = SPEED
$AnimatedSprite.play("Run")
$AnimatedSprite.flip_h = false
else:
velocity.x = 0
if on_ground == true:
if isAttacking == false:
$AnimatedSprite.play("Idle")
if Input.is_action_pressed("ui_up"):
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
if Input.is_action_just_pressed("Attack"):
if on_ground == true:
if $AnimatedSprite.flip_h == false:
$AnimatedSprite.play("Attack")
isAttacking = true
$Attack_Area_Right/Attack_Collision.disabled = false
if $AnimatedSprite.flip_h == true:
$AnimatedSprite.play("Attack")
isAttacking = true
$Attack_Area_Left/Attack_Collision.disabled = false
velocity.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false
if velocity.y < 0:
$AnimatedSprite.play("Jump")
else:
$AnimatedSprite.play("Fall")
velocity = move_and_slide(velocity, FLOOR)
func _on_AnimatedSprite_animation_finished():
if $AnimatedSprite.animation == “Attack”:
$Attack_Area_Right/Attack_Collision.disabled = true
isAttacking = false
if $AnimatedSprite.animation == “Attack”:
$Attack_Area_Left/Attack_Collision.disabled = true
isAttacking = false
I cannot reproduce your problem. Have you made sure the animation_finished
-signal is connected? If your player character doesn’t move anymore after pressing “Attack”, then that’s likely because isAttacking
is never reset to false
.
If you upload an example project, I can take a look.
njamster | 2020-06-04 16:42