It’s been a long while since I’ve opened up Godot. Would it be better to have the screenSize variable global instead of local. That way it’s only calculated once in the _ready function?
extends CharacterBody2D
var speed = 250
var screenSize
func _ready():
screenSize = get_viewport_rect().size
func _physics_process(delta):
velocity = Vector2(0,0)
if Input.is_action_pressed("move_right"):
velocity.x = speed
if Input.is_action_pressed("move_left"):
velocity.x = -speed
if Input.is_action_pressed("move_up"):
velocity.y = -speed
if Input.is_action_pressed("move_down"):
velocity.y = speed
move_and_slide()
global_position = global_position.clamp(Vector2(0,0), screenSize)