StickerClone/player.gd
2024-07-23 10:06:01 +02:00

28 lines
700 B
GDScript

extends CharacterBody2D
const SPEED = 500.0
func get_input():
var directionX = Input.get_axis("move_left", "move_right")
var directionY = Input.get_axis("move_up", "move_down")
# Get the input direction and handle the movement/deceleration.
if directionX :
velocity.x = directionX * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if directionY:
velocity.y = directionY * SPEED
else:
velocity.y = move_toward(velocity.y, 0, SPEED)
#region Animation
if (directionX < 0):
$Skeleton2D/root/Hips.set_scale(Vector2(1, 1))
if (directionX > 0):
$Skeleton2D/root/Hips.set_scale(Vector2(-1, 1))
#endregion
func _physics_process(delta):
get_input()
move_and_slide()