Snoweuph
b410c97074
All checks were successful
Export Game
Co-authored-by: snoweuph <snow+git@euph.email> Co-authored-by: Platinwing <csaeume@gmail.com> Reviewed-on: #36
24 lines
709 B
GDScript
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
|