This repository has been archived on 2023-10-28. You can view files and clone it, but cannot push or open issues or pull requests.
2DHackAndSlay/Scripts/Player/PlayerController.gd
Snoweuph b410c97074
All checks were successful
Export Game
dev-base (#36)
Co-authored-by: snoweuph <snow+git@euph.email>
Co-authored-by: Platinwing <csaeume@gmail.com>
Reviewed-on: #36
2023-04-05 21:01:02 +00:00

24 lines
709 B
GDScript

extends CharacterBody2D
@export var speed = 100
@export_range(0, 1) var damping_factor := 0.6
func get_move_vector():
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
return input_direction
func move_player(delta : float):
if get_move_vector() == Vector2.ZERO:
# Damp Players Velocity if no Input
self.velocity = self.velocity * (1 - min(1, damping_factor * 60 * delta))
else:
# Set Players Velocity to the Input Direction in the Players Speed
self.velocity = get_move_vector() * speed * delta * 60
# Update The Players Physics Calculations
self.move_and_slide()
pass
func _physics_process(delta : float):
move_player(delta)
pass