how do i get this shit to false bruh

Godot Version

4.3

Question

everytime i try to attack my sprite would just either stay in the last frame of the attack or go back to idle but not do any other animations other the attack animation
Here’s the code
extends CharacterBody2D

@onready var sprite = $AnimatedSprite2D

@export var SPEED = 320.0
@export var JUMP_HEIGHT = -450.0

@export var attacking = false

func _process(_delta):
if Input.is_action_just_pressed(“attack”):
attack()
func _physics_process(_delta):
# MOVE PLAYER LEFT/RIGHT
if Input.is_action_pressed(“right”):
sprite.scale.x = abs(sprite.scale.x) * -1
if Input.is_action_pressed(“left”):
sprite.scale.x = abs(sprite.scale.x)
#$AnimatedSprite.flip_h = true

# Add the gravity.
if not is_on_floor():
	velocity += get_gravity() * _delta

# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_HEIGHT

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("right", "left")
if direction:
	velocity.x = direction * SPEED
else:
	sprite.play("idle")
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()
update_sprite()

func attack():
attacking = true
sprite.play(“1st_hit_in_combo”)

func update_sprite():
if !attacking:
if velocity.x !=0:
sprite.play(“run”)
else:
sprite.play(“idle”)

	if velocity.y < 0:
		sprite.play("jump")
	if velocity.y > 0:
		sprite.play("fall")

attacking is always = true ?

Try “StateMachine” https://youtu.be/oqFbZoA2lnU?si=pozdmtUfeo_ZmML1

1 Like

Hey, @Mr.chad69. Another commentor mentioned it, but it looks like what you need is a Finite State Machine. It’s a programming pattern that’s very common for video game characters.

Lots of videos available on YouTube explaining it. Worth learning for sure!