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

25 lines
709 B
GDScript3
Raw Permalink Normal View History

extends CharacterBody2D
@export var speed = 100
@export_range(0, 1) var damping_factor := 0.6
2023-02-02 22:09:00 +00:00
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()
2023-02-02 22:09:00 +00:00
pass
func _physics_process(delta : float):
move_player(delta)
pass