Files
Cozypaw-Hospital/scripts/systems/room_navigator.gd
Steven Wroblewski 6bc199f6c1 fix(core): correct camera Y offset in RoomNavigator floor navigation
Floor N spans from N*-720 to (N-1)*-720. The camera must center at the
floor midpoint, so target_y = floor_index * -720 + 360 (half floor height).
Previous formula placed the camera at the floor boundary, showing content
split between two floors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 13:26:03 +02:00

31 lines
854 B
GDScript

## RoomNavigator — autoload that moves the Camera2D smoothly between hospital floors.
extends Node
signal room_changed(floor_index: int)
const FLOOR_HEIGHT: float = 720.0
const CAMERA_TWEEN_DURATION: float = 0.6
var _current_floor: int = 0
var _camera: Camera2D
func initialize(camera: Camera2D) -> void:
_camera = camera
func go_to_floor(floor_index: int) -> void:
if _camera == null or floor_index == _current_floor:
return
_current_floor = floor_index
var target_y: float = floor_index * -FLOOR_HEIGHT + FLOOR_HEIGHT * 0.5
var tween: Tween = create_tween()
tween.set_ease(Tween.EASE_IN_OUT)
tween.set_trans(Tween.TRANS_SINE)
tween.tween_property(_camera, "position:y", target_y, CAMERA_TWEEN_DURATION)
tween.finished.connect(func() -> void: room_changed.emit(floor_index))
func get_current_floor() -> int:
return _current_floor