StickerClone/player.gd

31 lines
797 B
GDScript3
Raw Normal View History

2024-07-19 23:01:49 +00:00
extends CharacterBody2D
2024-07-23 09:01:03 +00:00
const SPEED = 700.0
2024-07-19 23:01:49 +00:00
2024-07-23 08:06:01 +00:00
func get_input():
2024-07-22 14:48:39 +00:00
var directionX = Input.get_axis("move_left", "move_right")
var directionY = Input.get_axis("move_up", "move_down")
2024-07-23 08:06:01 +00:00
# Get the input direction and handle the movement/deceleration.
2024-07-19 23:01:49 +00:00
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)
2024-07-23 08:06:01 +00:00
#region Animation
if (directionX < 0):
$Skeleton2D/root/Hips.set_scale(Vector2(1, 1))
if (directionX > 0):
$Skeleton2D/root/Hips.set_scale(Vector2(-1, 1))
2024-07-23 09:01:03 +00:00
$AnimationTree.set("parameters/WalkRun/blend_position",max(abs(velocity.x),abs(velocity.y)))
2024-07-23 08:06:01 +00:00
#endregion
2024-07-22 20:14:04 +00:00
2024-07-23 08:06:01 +00:00
func _physics_process(delta):
get_input()
2024-07-19 23:01:49 +00:00
move_and_slide()