StickerClone/player.gd

33 lines
790 B
GDScript

extends CharacterBody2D
const SPEED = 500.0
func _physics_process(delta):
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var directionX = Input.get_axis("ui_left", "ui_right")
var directionY = Input.get_axis("ui_up", "ui_down")
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)
#if velocity.x > 0:
#$AnimationPlayer.play("player_WalkRight")
#if velocity.x < 0 :
#$AnimationPlayer.play("player_WalkLeft")
#if (velocity.x == 0 and velocity.y == 0):
#$AnimationPlayer.play("idle")
move_and_slide()