summaryrefslogtreecommitdiffstats
path: root/game_camera.gd
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-11-14 14:05:22 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-11-14 14:05:22 +0200
commit9d71ad993ec77108874db9697256b4fef385ce16 (patch)
tree72bd20d86c7f1e5b8e3c433f98d138eaae06e43a /game_camera.gd
parentc80c35213bb13ca7db939639d5a707f6944f8196 (diff)
Add camera offsetting when moving
Diffstat (limited to 'game_camera.gd')
-rw-r--r--game_camera.gd34
1 files changed, 34 insertions, 0 deletions
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)