update player animations and set physics fps to 144
This commit is contained in:
@@ -4,6 +4,7 @@ extends CharacterBody2D
|
||||
@export var speed = 300.0
|
||||
@export var jump_velocity = -400.0
|
||||
|
||||
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
@@ -11,15 +12,32 @@ func _physics_process(delta: float) -> void:
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = jump_velocity
|
||||
|
||||
# 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("ui_left", "ui_right")
|
||||
var direction := Input.get_axis("move_left", "move_right")
|
||||
|
||||
if direction > 0:
|
||||
animated_sprite.flip_h = false
|
||||
elif direction < 0:
|
||||
animated_sprite.flip_h = true
|
||||
|
||||
set_animation(direction)
|
||||
|
||||
if direction:
|
||||
velocity.x = direction * speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, speed)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func set_animation(direction: float):
|
||||
if is_on_floor():
|
||||
if direction == 0:
|
||||
animated_sprite.play("idle")
|
||||
else:
|
||||
animated_sprite.play("run")
|
||||
else:
|
||||
animated_sprite.play("jump")
|
||||
|
||||
Reference in New Issue
Block a user