25 lines
765 B
GDScript
25 lines
765 B
GDScript
extends KinematicBody2D
|
|
|
|
const ACCELERATION = 1000
|
|
const MAX_SPEED = 120
|
|
const FRICTION = 200
|
|
|
|
var velocity: Vector2 = Vector2.ZERO
|
|
|
|
|
|
func _physics_process(delta) -> void:
|
|
var input_vector: Vector2 = Vector2.ZERO
|
|
|
|
input_vector.x = Input.get_action_strength('player_right') - Input.get_action_strength('player_left')
|
|
input_vector.y = Input.get_action_strength('player_down') - Input.get_action_strength('player_up')
|
|
input_vector = input_vector.normalized()
|
|
|
|
if input_vector != Vector2.ZERO:
|
|
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
|
|
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
|
else:
|
|
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
|
|
|
velocity = move_and_slide(velocity)
|
|
return
|