- Android back: application/config/quit_on_go_back=false; Main.go_back() (from NOTIFICATION_WM_GO_BACK_REQUEST, phones only) closes the shop or pouch panel or leaves build mode, else pauses; paused it closes the question, then settings, then resumes (shared with the pause action); at the main menu it closes the question or settings, else quits. - Phones hide the main menu's Quit and the pause menu's Quit the game. - ScreenLabels.ensure() makes the one ScreenLabels (ToonLook's on desktop; Main's on phones, which watch()es the tree for Label3Ds). Label sizes grow with the window's content_scale_factor (1 on desktop). - FollowCamera starts at PHONE_DISTANCE (12 m) on phones. - MobilePort.forced for tests; game/tests/mobile/platform_test.gd. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.2 KiB
GDScript
65 lines
2.2 KiB
GDScript
@tool
|
|
class_name FollowCamera
|
|
extends Camera3D
|
|
## Angled top-down camera that trails a target. The framing comes entirely from pitch / yaw /
|
|
## distance (the transform is overwritten every frame, also in the editor so the framing can be
|
|
## previewed). PlayerCharacter moves relative to this camera's yaw. Mouse wheel zooms. On a phone
|
|
## (MobilePort) it starts closer, at PHONE_DISTANCE.
|
|
|
|
## The phones' distance (the small screen), in place of distance's default when the game starts.
|
|
const PHONE_DISTANCE := 12.0
|
|
|
|
@export var target: Node3D
|
|
@export_range(5.0, 89.0) var pitch_deg := 50.0
|
|
@export_range(-180.0, 180.0) var yaw_deg := 45.0
|
|
@export var distance := 16.0
|
|
@export var min_distance := 6.0
|
|
@export var max_distance := 40.0
|
|
@export var zoom_step := 1.5
|
|
## Height above the target's origin that the camera looks at.
|
|
@export var look_height := 1.0
|
|
## How quickly the camera catches up with the target (higher = tighter, 0 = locked on).
|
|
@export var follow_speed := 6.0
|
|
|
|
var _focus := Vector3.ZERO
|
|
|
|
|
|
func _ready() -> void:
|
|
physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
|
|
if not Engine.is_editor_hint() and MobilePort.active():
|
|
distance = PHONE_DISTANCE
|
|
snap_to_target()
|
|
|
|
|
|
## Jumps straight to the target (use after teleporting it).
|
|
func snap_to_target() -> void:
|
|
if target != null:
|
|
_focus = target.global_position + Vector3.UP * look_height
|
|
_apply()
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if target != null:
|
|
var origin := target.global_position if Engine.is_editor_hint() \
|
|
else target.get_global_transform_interpolated().origin
|
|
var goal := origin + Vector3.UP * look_height
|
|
if follow_speed <= 0.0 or Engine.is_editor_hint():
|
|
_focus = goal
|
|
else:
|
|
_focus = _focus.lerp(goal, 1.0 - exp(-follow_speed * delta))
|
|
_apply()
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
var mb := event as InputEventMouseButton
|
|
if mb == null or not mb.pressed:
|
|
return
|
|
if mb.button_index == MOUSE_BUTTON_WHEEL_UP:
|
|
distance = maxf(distance - zoom_step, min_distance)
|
|
elif mb.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
|
distance = minf(distance + zoom_step, max_distance)
|
|
|
|
|
|
func _apply() -> void:
|
|
var b := Basis.from_euler(Vector3(deg_to_rad(-pitch_deg), deg_to_rad(yaw_deg), 0.0))
|
|
global_transform = Transform3D(b, _focus + b.z * distance)
|