CyberTower/scripts/PlayerMovement.gd

30 lines
837 B
GDScript3
Raw Normal View History

2024-02-16 10:10:00 +00:00
extends CharacterBody2D
@export var speed = 1200
@export var speed_multiplier = 20
@export var friction = 0.9
@export var dash_cooldown_duration = 1.0
@export var dash_cooldown_timer: Timer
func deal_move(delta):
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = velocity.move_toward(input_direction * speed, speed * delta)
velocity = velocity * friction
var is_dash = Input.is_action_pressed("skill_dash")
if is_dash && dash_cooldown_timer.is_stopped():
velocity *= speed_multiplier
dash_cooldown_timer.start(dash_cooldown_duration)
func _on_cooled_down():
dash_cooldown_timer.stop()
func _ready():
var screen_size = get_viewport_rect().size
position = Vector2(screen_size.x / 2, screen_size.y / 2)
func _physics_process(delta):
deal_move(delta)
move_and_slide()