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 5b22a39a9d - Scale Movement by Delta Time
- Make Player Movement Damped
2023-02-04 20:02:29 +01: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