From 9d71ad993ec77108874db9697256b4fef385ce16 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 14 Nov 2025 14:05:22 +0200 Subject: Add camera offsetting when moving --- game_camera.gd | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 game_camera.gd (limited to 'game_camera.gd') diff --git a/game_camera.gd b/game_camera.gd new file mode 100644 index 0000000..9e6fd2b --- /dev/null +++ b/game_camera.gd @@ -0,0 +1,34 @@ +extends Camera2D + +@onready var parent = get_parent() +@onready var is_parent_player = parent is Player + +## Amount to smoothly offset the camera if the parent is a Player. +@export var offset_amt: Vector2 + +var time_since_floor: float = 0.0 +var time_since_floor_max: float = 1.0 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta: float) -> void: + #if player.is_on_floor(): + # time_since_floor = 0 + #elif time_since_floor < time_since_floor_max: + # time_since_floor += delta + + if is_parent_player: + var player: Player = parent + position.x = player.get_facing() * offset_amt.x + + if not player.is_on_floor(): + position.y = offset_amt.y + else: + position.y = 0 + + #offset.y = lerpf(0.0, look_down_on_jump_amt, ease(time_since_floor, 0.2)) + #print_debug("offset y:", offset.y) -- cgit v1.3