From 2382f9d3c1e006a29390c812c3a500962fa64ac5 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 24 Apr 2020 09:45:16 +0200 Subject: [PATCH] Now the camera gets instantiated when needed automatically by the body script. --- game/data/camera/CameraPivot.tscn | 14 ++++++++++++++ game/player/Body.gd | 15 +++++++++++++-- game/player/Mob.tscn | 2 -- game/player/NetworkedPlayer.tscn | 2 -- game/player/Player.tscn | 16 +--------------- 5 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 game/data/camera/CameraPivot.tscn diff --git a/game/data/camera/CameraPivot.tscn b/game/data/camera/CameraPivot.tscn new file mode 100644 index 00000000..91ecbe3f --- /dev/null +++ b/game/data/camera/CameraPivot.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://player/CameraPivot.gd" type="Script" id=1] + +[node name="CameraPivot" type="Spatial"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.44092, 0 ) +script = ExtResource( 1 ) + +[node name="Camera" type="Camera" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6.822 ) +current = true +fov = 60.0 +size = 28.0 +far = 1000.0 diff --git a/game/player/Body.gd b/game/player/Body.gd index 0a6878ba..db12fb79 100644 --- a/game/player/Body.gd +++ b/game/player/Body.gd @@ -23,8 +23,6 @@ extends KinematicBody - - export(float) var max_visible_distance : float = 120 setget set_max_visible_distance var max_visible_distance_squared : float = max_visible_distance * max_visible_distance @@ -573,6 +571,19 @@ func on_c_controlled_changed(val): # set_physics_process(val) set_process_input(val) set_process_unhandled_input(val) + + if val: + var cam_scene : PackedScene = ResourceLoader.load("res://data/camera/CameraPivot.tscn") + camera_pivot = cam_scene.instance() as Spatial + add_child(camera_pivot) + + camera = camera_pivot.get_node("Camera") as Camera + else: + if camera_pivot: + camera_pivot.queue_free() + camera_pivot = null + camera = null + func on_sdied(entity): if dead: diff --git a/game/player/Mob.tscn b/game/player/Mob.tscn index 15fe749a..5ecb63e8 100644 --- a/game/player/Mob.tscn +++ b/game/player/Mob.tscn @@ -39,5 +39,3 @@ transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 0, 0 [node name="Model" type="Spatial" parent="Body/Rotation_Helper"] [node name="character" parent="Body/Rotation_Helper/Model" instance=ExtResource( 1 )] -refresh_in_editor = false -use_lod = true diff --git a/game/player/NetworkedPlayer.tscn b/game/player/NetworkedPlayer.tscn index 7326561d..65d78dd5 100644 --- a/game/player/NetworkedPlayer.tscn +++ b/game/player/NetworkedPlayer.tscn @@ -35,8 +35,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.960532, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.875205, 0 ) [node name="character" parent="Body/Rotation_Helper/Model" instance=ExtResource( 2 )] -refresh_in_editor = false -use_lod = true [node name="NamePlate" parent="." instance=ExtResource( 3 )] max_distance = 50.0 diff --git a/game/player/Player.tscn b/game/player/Player.tscn index 2d07ec05..7a57cfac 100644 --- a/game/player/Player.tscn +++ b/game/player/Player.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://data/models/armature_model_orig_v2.tscn" type="PackedScene" id=1] [ext_resource path="res://player/Player.gd" type="Script" id=2] [ext_resource path="res://ui/player_ui/player_ui.tscn" type="PackedScene" id=3] -[ext_resource path="res://player/CameraPivot.gd" type="Script" id=4] [ext_resource path="res://player/Body.gd" type="Script" id=5] [sub_resource type="CapsuleShape" id=1] @@ -31,25 +30,12 @@ shape = SubResource( 1 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0 ) shape = SubResource( 2 ) -[node name="CameraPivot" type="Spatial" parent="Body"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.44092, 0 ) -script = ExtResource( 4 ) - -[node name="Camera" type="Camera" parent="Body/CameraPivot"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6.822 ) -current = true -fov = 60.0 -size = 28.0 -far = 1000.0 - [node name="Rotation_Helper" type="Spatial" parent="Body"] transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 0, 0 ) [node name="Model" type="Spatial" parent="Body/Rotation_Helper"] [node name="character" parent="Body/Rotation_Helper/Model" instance=ExtResource( 1 )] -refresh_in_editor = false -use_lod = true [node name="GUILayer" parent="." instance=ExtResource( 3 )] [connection signal="onc_open_loot_winow_request" from="." to="GUILayer" method="_on_Player_onc_open_loot_winow_request"]