diff options
Diffstat (limited to 'PlayerMovement.gd')
-rw-r--r-- | PlayerMovement.gd | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/PlayerMovement.gd b/PlayerMovement.gd new file mode 100644 index 0000000..df9b002 --- /dev/null +++ b/PlayerMovement.gd @@ -0,0 +1,23 @@ +extends Node + +@export var speed : float +@export var velocity_dampening : float + +var target_velocity : Vector2 +var velocity : Vector2 + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + var input : Vector2 = Input.get_vector("left", "right", "up", "down") + target_velocity = input * delta * speed + + if input != Vector2.ZERO: + velocity = velocity.lerp(target_velocity, velocity_dampening * 2) + else: + velocity = velocity.lerp(target_velocity, velocity_dampening) + + $"..".position += velocity |