fix: animation debug + F1 third-person camera
SkinnedPlayerModel: - Added _print_tree debug to see GLB scene structure at runtime - Auto-play Idle animation on load - Added periodic debug output for animation state - Only change animation when target differs from current Third-person camera: - F1 toggles between FPS and third-person view - Third-person camera positioned behind/above player - Smooth follow with lerp - Camera tracks player position each frame
This commit is contained in:
@@ -17,7 +17,9 @@ var _fps_label: Label
|
||||
var _standalone_speed_label: Label
|
||||
var _player: CharacterBody3D
|
||||
var _debug_ui_panel: PanelContainer
|
||||
|
||||
var _third_person: bool = false
|
||||
var _third_person_camera: Camera3D
|
||||
var _fps_camera: Camera3D
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
@@ -45,6 +47,61 @@ func _ready() -> void:
|
||||
p.queue_free()
|
||||
)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_F1:
|
||||
_toggle_third_person()
|
||||
|
||||
func _toggle_third_person() -> void:
|
||||
_third_person = not _third_person
|
||||
|
||||
# Find cameras
|
||||
if not _fps_camera:
|
||||
_fps_camera = _find_camera_in_player()
|
||||
if not _third_person_camera:
|
||||
_setup_third_person_camera()
|
||||
|
||||
if _third_person:
|
||||
# Switch to third person
|
||||
if _fps_camera:
|
||||
_fps_camera.current = false
|
||||
if _third_person_camera:
|
||||
_third_person_camera.current = true
|
||||
print("Third person: ON")
|
||||
else:
|
||||
# Switch to first person
|
||||
if _third_person_camera:
|
||||
_third_person_camera.current = false
|
||||
if _fps_camera:
|
||||
_fps_camera.current = true
|
||||
print("Third person: OFF")
|
||||
|
||||
func _find_camera_in_player() -> Camera3D:
|
||||
if not _player:
|
||||
return null
|
||||
# Search for Camera3D in player's children
|
||||
for child in _player.get_children():
|
||||
if child is Camera3D:
|
||||
return child
|
||||
for grandchild in child.get_children():
|
||||
if grandchild is Camera3D:
|
||||
return grandchild
|
||||
return null
|
||||
|
||||
func _setup_third_person_camera() -> void:
|
||||
if not _player:
|
||||
return
|
||||
_third_person_camera = Camera3D.new()
|
||||
_third_person_camera.name = "ThirdPersonCamera"
|
||||
_third_person_camera.fov = 75.0
|
||||
_third_person_camera.near = 0.1
|
||||
_third_person_camera.far = 200.0
|
||||
# Position behind and above the player
|
||||
_third_person_camera.position = Vector3(0, 2.0, -4.0)
|
||||
_third_person_camera.look_at(Vector3(0, 1.0, 0))
|
||||
_player.add_child(_third_person_camera)
|
||||
_third_person_camera.current = false
|
||||
|
||||
|
||||
func _build_materials() -> void:
|
||||
pass
|
||||
@@ -690,6 +747,12 @@ func _process(_delta: float) -> void:
|
||||
if not _player or not is_instance_valid(_player):
|
||||
return
|
||||
|
||||
# Third person camera follow
|
||||
if _third_person and _third_person_camera and _third_person_camera.current:
|
||||
var target_pos = _player.global_position + Vector3(0, 2.0, -4.0)
|
||||
_third_person_camera.global_position = _third_person_camera.global_position.lerp(target_pos, 0.1)
|
||||
_third_person_camera.look_at(_player.global_position + Vector3(0, 1.0, 0))
|
||||
|
||||
if _debug_ui_panel:
|
||||
_debug_ui_panel.visible = SettingsManager.show_debug_ui
|
||||
|
||||
|
||||
Reference in New Issue
Block a user