\$\begingroup\$

extends CharacterBody2D


@export var SPEED = 300.0
@export var maxHP = 100
@export var curHP = 100

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var state_machine = $AnimationTree.get("parameters/playback")

func _ready():
    pass


func _physics_process(delta):
    if not is_on_floor():
        velocity.y += gravity * delta
    
    var direction = Input.get_axis("ui_left", "ui_right")
    if direction:
        velocity.x = direction * SPEED
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)
    
    if velocity.length() > 0:
        state_machine.travel("run")
    else:
        state_machine.travel("idle")
        
    
    if Input.is_action_pressed("ui_left"):
        $Sprite2D.set("flip_h", true)
    if Input.is_action_pressed("ui_right"):
        $Sprite2D.set("flip_h", false)
    
    
    move_and_slide()
    
    if Input.is_action_just_pressed("attack"):
        _shoot()

func _losehp():
    curHP -= 10

func _die():
    if curHP == 0:
        pass

func _shoot():
    if Input.is_action_just_pressed("attack"):
        pass

enter image description here

enter image description here

enter image description here

please help:(

\$\endgroup\$

You must log in to answer this question.

Browse other questions tagged .