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.

If you want the camera to move with the player, make the camera a child of the player node. Then there's no need for a camera script.

Welcome to the forums @Illusi0n!

You probably will want to use global_position instead of position in your camera script. Global position is relative to the scene origin, while position is relative to the node’s parent.

@DaveTheCoder said: If you want the camera to move with the player, make the camera a child of the player node. Then there's no need for a camera script.

When I do that, the same results happen.

@TwistedTwigleg said: Welcome to the forums @Illusi0n!

You probably will want to use global_position instead of position in your camera script. Global position is relative to the scene origin, while position is relative to the node’s parent.

It still doesn't work...

Do you have a background? Because if the camera is following the player position exactly, it won't look like either is moving unless you have a background to see what's happening.

@cybereality said: Do you have a background? Because if the camera is following the player position exactly, it won't look like either is moving unless you have a background to see what's happening.

I put an object outside of the camera limit, but I can't see it when I walk up.

Did you check "current" for the Camera?

@exuin said: Did you check "current" for the Camera?

Yes

@Illusi0n said: 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.

FIXED! I reinstalled it. Must've been a bug... Thanks everyone!

2 years later