Frist 2D game: Player movement is limited to bottom right

Godot Version



I’m working along the tutorial for my first 2D game, the player spawns in a point he think is (0,0), however this is the middle of the screen. The player can then move right or down, but not left or up.
I think something in the positions of the tutorial is wrong, but can’t figure out what it is.
extends Node2D

@export var mob_scene: PackedScene
var score

Called when the node enters the scene tree for the first time.

func _ready():

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):

func game_over():

func new_game():
score = 0

func _on_start_timer_timeout():

func _on_score_timer_timeout():
score += 1

func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()

# Choose a random location on Path2D.
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()

# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2

# Set the mob's position to a random location.
mob.position = mob_spawn_location.position

# Add some randomness to the direction.
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction

# Choose the velocity for the mob.
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)

# Spawn the mob by adding it to the Main scene.

extends Area2D
signal hit

@export var speed = 400 # How fast the player will move (pixels/sec).
var screen_size # Size of the game window.

Called when the node enters the scene tree for the first time.

func _ready():
screen_size = get_viewport_rect().size # Get the screen size

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
var velocity = Vector2.ZERO # The player’s movement vector.
if Input.is_action_pressed(“move_right”):
velocity.x += 1
if Input.is_action_pressed(“move_left”):
velocity.x -= 1
if Input.is_action_pressed(“move_down”):
velocity.y += 1
if Input.is_action_pressed(“move_up”):
velocity.y -= 1

if velocity.length() > 0:
	velocity = velocity.normalized() * speed

# Move the player by the calculated velocity, taking delta time into account.
position += velocity * delta
# Clamp the player's position to ensure it stays within the screen bounds.
position = position.clamp(Vector2.ZERO, screen_size)
if velocity.x != 0:
	$AnimatedSprite2D.animation = "walk"
	$AnimatedSprite2D.flip_v = false
	# See the note below about boolean assignment.
	$AnimatedSprite2D.flip_h = velocity.x < 0
elif velocity.y != 0:
	$AnimatedSprite2D.animation = "up"
	$AnimatedSprite2D.flip_v = velocity.y > 0

func _on_body_entered(body):
hide() # Player disappears after being hit.
# Must be deferred as we can’t change physics properties on a physics callback.
$CollisionShape2D.set_deferred(“disabled”, true)

func start(pos):
position = pos
$CollisionShape2D.disabled = false

Thanks everyone!

After sleeping I have more information:
So I made a mistake and created Main as a Node2D instead of Node.
I’m new to programming in GODOT (obviously) and it seems the origin of the node (it’s 0,0 position) is (240,450).
This causes StartPosition (which is 240,450) to be out of the screen.

I changed the node type and this fixed the game, but I’m still wondering what is the cause of this.