StickerClone/player.gd

38 lines
998 B
GDScript3
Raw Normal View History

2024-07-19 23:01:49 +00:00
extends CharacterBody2D
const SPEED = 500.0
func _physics_process(delta):
2024-07-22 14:48:39 +00:00
#region Movement
2024-07-19 23:01:49 +00:00
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
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-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-22 14:48:39 +00:00
#endregion
2024-07-22 20:14:04 +00:00
2024-07-22 21:08:48 +00:00
#region Animation
var WalkLeft = directionX < 0 or (directionY < 0 and directionY != 0)
var Idle = (velocity.x == 0 and velocity.y == 0)
$AnimationTree.set("parameters/Locomotion/conditions/Idle",Idle)
$AnimationTree.set("parameters/Locomotion/conditions/WalkLeft",WalkLeft and !Idle )
$AnimationTree.set("parameters/Locomotion/conditions/WalkRight",!WalkLeft and !Idle)
2024-07-22 20:14:04 +00:00
2024-07-22 21:08:48 +00:00
#endregion
2024-07-22 14:48:39 +00:00
2024-07-19 23:01:49 +00:00
move_and_slide()