gd 4.5.1
extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var oww: AudioStreamPlayer2D = $oww
@onready var progress_bar: ProgressBar = $"../ui/Panel/ProgressBar"
const SPEED = 150.0
const JUMP_VELOCITY = -330.0
@onready var character_body_2d: CharacterBody2D = $"."
var Heath = 100
func _physics_process(delta: float) -> void:
progress_bar.value = Heath
if (velocity.x > 1 || velocity.x < -1):
animated_sprite_2d.animation ="running"
else:
animated_sprite_2d.animation ="default"
if not is_on_floor():
velocity += get_gravity() * delta
animated_sprite_2d.animation ="jumping"
if Heath <= 0:
get_tree().change_scene_to_file("res://scenes/main_menu.tscn")
if Input.is_action_just_pressed("j") and is_on_floor():
velocity.y = JUMP_VELOCITY
animated_sprite_2d.animation ="jumping"
# 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("l", "r")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
var isleft = velocity.x < 0
animated_sprite_2d.flip_h = isleft
move_and_slide()
This is my code if you can see any error I would love the help. I am kind of new.
All other animations work fine but it just ether play walking of idle(default) animations when I jump. Don’t know if this help but I use A, D, and space bar for controls. If you have any tips I would love to here them.