[ad_1]
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
5 times
\$\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
please help:(
\$\endgroup\$
default
[ad_2]