29 lines
638 B
GDScript
29 lines
638 B
GDScript
extends KinematicBody2D
|
|
|
|
var speed = 35;
|
|
var velocity = Vector2()
|
|
|
|
func _ready():
|
|
pass
|
|
|
|
func _physics_process(delta):
|
|
velocity = Vector2()
|
|
|
|
# Input
|
|
if Input.is_action_pressed("down"):
|
|
velocity.y += speed
|
|
if Input.is_action_pressed("up"):
|
|
velocity.y -= speed
|
|
if Input.is_action_pressed("left"):
|
|
velocity.x -= speed
|
|
if Input.is_action_pressed("right"):
|
|
velocity.x += speed
|
|
|
|
# Animation
|
|
if Input.is_action_pressed("right") || Input.is_action_pressed("left") \
|
|
|| Input.is_action_pressed("up") || Input.is_action_pressed("down"):
|
|
$AnimationPlayer.play("Walk")
|
|
else:
|
|
$AnimationPlayer.stop()
|
|
|
|
move_and_slide(velocity)
|