summaryrefslogtreecommitdiff
path: root/PlayerMovement.gd
blob: df9b002dd8c3eb6a1b2f786e56503cddf3d66109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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