I have been trying to figure it out for a long time, but I still can't figure it out. My character just doesn't move.
My character code:
extends KinematicBody2D
export var speed = 200
export var friction = 0.01
export var acceleration = 0.1
var velocity = Vector2()
func get_input():
var input = Vector2()
if Input.is_action_pressed('d'):
input.x += 1
if Input.is_action_pressed('a'):
input.x -= 1
if Input.is_action_pressed('s'):
input.y += 1
if Input.is_action_pressed('w'):
input.y -= 1
return input
func _physics_process(delta):
var direction = get_input()
if direction.length() > 0:
velocity = lerp(velocity, direction.normalized() * speed, acceleration)
else:
velocity = lerp(velocity, Vector2.ZERO, friction)
velocity = move_and_slide(velocity)
And Camera2D:
extends Camera2D
onready var player = get_node("/root/World/Player")
func _physics_process(delta):
position.x = player.position.x
position.y = player.position.y
Thanks.