Player freezes when attack is pressed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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.flip_h = true

elif Input.is_action_pressed("ui_right") && isAttacking == false :
		velocity.x = SPEED
		$AnimatedSprite.flip_h = false
	velocity.x = 0
	if on_ground == true:
		if isAttacking == false:
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:
			isAttacking = true
			$Attack_Area_Right/Attack_Collision.disabled = false
		if $AnimatedSprite.flip_h == true:
			isAttacking = true
			$Attack_Area_Left/Attack_Collision.disabled = false

velocity.y += GRAVITY

if is_on_floor():
	on_ground = true
	on_ground = false
	if velocity.y < 0:

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

:bust_in_silhouette: Reply From: Becbunzen

Maybe change both

&& isAttacking == false


&& (isAttacking == false)

could help?

Hi, thanks for the suggestion but still no luck.

LifeRips | 2020-06-04 06:12

Your code is a bit hard to read, with some not in code block. Try to comment out all effects of attacking, just print out that attack was pressed, and if that work add back the functionality you want until all is there. Then you will see which part is problematic.

Becbunzen | 2020-06-04 06:44

Putting the condition in parentheses won’t do anything.

See: GDScript style guide — Godot Engine (stable) documentation in English

njamster | 2020-06-04 16:44