diff --git a/Intro.tscn b/Intro.tscn index f5d2a00..39d8d2d 100644 --- a/Intro.tscn +++ b/Intro.tscn @@ -6,21 +6,22 @@ [sub_resource type="Animation" id="Animation_gojcw"] resource_name = "new_animation" -length = 30.0 +length = 35.0 +loop_mode = 1 tracks/0/type = "position_3d" tracks/0/imported = false tracks/0/enabled = true tracks/0/path = NodePath(".") -tracks/0/interp = 1 +tracks/0/interp = 2 tracks/0/loop_wrap = true -tracks/0/keys = PackedFloat32Array(0, 1, 0.454, 1.517, -2.572, 1.5, 1, 0.454, 1.97523, 0.966014, 4.1, 1, 0.454, 3.2871, 2.84737, 7, 1, 1.92063, 3.43251, -0.523631, 8.3, 1, 2.35502, 3.52832, -2.74459, 10.2, 1, 2.68438, 3.61438, -4.73982, 12.1, 1, -0.0351753, 2.63149, -7.11426, 13.8, 1, -2.18601, 1.36965, -7.92156, 15.5, 1, -2.94256, 1.67447, -7.82756, 17.4, 1, -1.44099, 3.73792, -4.08864, 20, 1, -3.30595, 4.72699, -0.869471, 30, 1, -0.569977, 4.72699, 5.4241) +tracks/0/keys = PackedFloat32Array(0, 1, 0.454, 1.517, -2.572, 1.5, 1, 0.454, 1.97523, 0.966014, 4.1, 1, 0.454, 3.2871, 2.84737, 7, 1, 1.92063, 3.43251, -0.523631, 8.3, 1, 2.35502, 3.52832, -2.74459, 10.2, 1, 2.68438, 3.61438, -4.73982, 12.1, 1, -0.0351753, 2.63149, -7.11426, 13.8, 1, -2.18601, 1.36965, -7.92156, 15.5, 1, -2.94256, 1.67447, -7.82756, 17.4, 1, -1.44099, 3.73792, -4.08864, 20, 1, -3.30595, 4.72699, -0.869471, 30, 1, -0.569977, 4.72699, 5.4241, 35, 1, 0.454, 1.517, -2.572) tracks/1/type = "rotation_3d" tracks/1/imported = false tracks/1/enabled = true tracks/1/path = NodePath(".") tracks/1/interp = 1 tracks/1/loop_wrap = true -tracks/1/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1, 1.5, 1, 0.0793464, 0, 0, 0.996847, 4.1, 1, 0.159502, 0, 0, 0.987198, 7, 1, 0.0211018, -0.203535, -0.00438783, 0.978831, 8.4, 1, 0.0215521, -0.00968415, -0.00020877, 0.999721, 10.2, 1, 0.0195802, 0.417873, 0.00900857, 0.90825, 12, 1, -0.294469, 0.389197, 0.152396, 0.859412, 13.8, 1, -0.294918, 0.950294, -0.0275901, -0.0959363, 15.5, 1, -0.178057, 0.983183, -0.0161448, 0.0372412, 17.4, 1, -0.138516, 0.933496, -0.294042, -0.151455, 20, 1, -0.121745, -0.52284, 0.301373, 0.78803, 30, 1, 0, 0, 0, 1) +tracks/1/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1, 1.5, 1, 0.0793464, 0, 0, 0.996847, 4.1, 1, 0.159502, 0, 0, 0.987198, 7, 1, 0.0211018, -0.203535, -0.00438783, 0.978831, 8.4, 1, 0.0215521, -0.00968415, -0.00020877, 0.999721, 10.2, 1, 0.0195802, 0.417873, 0.00900857, 0.90825, 12, 1, -0.294469, 0.389197, 0.152396, 0.859412, 13.8, 1, -0.294918, 0.950294, -0.0275901, -0.0959363, 15.5, 1, -0.178057, 0.983183, -0.0161448, 0.0372412, 17.4, 1, -0.138516, 0.933496, -0.294042, -0.151455, 20, 1, -0.121745, -0.52284, 0.301373, 0.78803, 30, 1, 0, 0, 0, 1, 35, 1, 0, 0, 0, 1) [sub_resource type="AnimationLibrary" id="AnimationLibrary_53h31"] _data = { @@ -37,10 +38,10 @@ root_node = NodePath("../Camera3D") libraries = { "": SubResource("AnimationLibrary_53h31") } -speed_scale = 0.1 +speed_scale = 0.5 [node name="Camera3D" type="Camera3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.569977, 4.72699, 5.4241) +transform = Transform3D(0.488773, -0.343267, -0.80204, 0.521973, 0.851698, -0.0464236, 0.699031, -0.395953, 0.595463, -3.75333, 5.21263, 1.27759) [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = ExtResource("2_stw21") diff --git a/assets/Player.tscn b/assets/Player.tscn index 01de0c4..dd90402 100644 --- a/assets/Player.tscn +++ b/assets/Player.tscn @@ -11,13 +11,16 @@ size = Vector3(0.4, 1.8, 0.4) [node name="Player" type="CharacterBody3D"] script = ExtResource("1_la1lv") -[node name="Camera3D" type="Camera3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.899966, 0) - [node name="CollisionShape3D" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.899966, 0) shape = SubResource("ConvexPolygonShape3D_5mrtf") -[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"] +[node name="Pivot" type="Node3D" parent="."] + +[node name="Camera" type="Camera3D" parent="Pivot"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.899966, 0) +cull_mask = 1048573 + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Pivot/Camera"] mesh = SubResource("PrismMesh_c7ovg") -skeleton = NodePath("../..") +skeleton = NodePath("../../..") diff --git a/levels/TestLevel.tscn b/levels/TestLevel.tscn index a243b0c..137f937 100644 --- a/levels/TestLevel.tscn +++ b/levels/TestLevel.tscn @@ -42,9 +42,6 @@ data = PackedVector3Array(-10, 2.5, 0.5, 10, 2.5, 0.5, -10, -2.5, 0.5, 10, 2.5, [node name="Node3D" type="Node3D"] script = ExtResource("1_0vmht") -[node name="NetworkedNodes" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) - [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = ExtResource("3_8gl6a") @@ -68,8 +65,16 @@ fov = 96.3 near = 1.0 far = 300.0 +[node name="PlayerSpawner" type="MultiplayerSpawner" parent="."] +spawn_path = NodePath("Players") + +[node name="Players" type="Node3D" parent="PlayerSpawner"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) + [node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."] -spawn_path = NodePath("../NetworkedNodes") +spawn_path = NodePath("Guards") + +[node name="Guards" type="Node3D" parent="MultiplayerSpawner"] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, -0.999, 0.0447004, 0, -0.0447004, -0.999, 0, 14.0621, -6.13505) diff --git a/project.godot b/project.godot index 91d14c8..ae01b56 100644 --- a/project.godot +++ b/project.godot @@ -65,3 +65,8 @@ look_right={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) ] } +mode={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} diff --git a/src/GameLogic.gd b/src/GameLogic.gd index 985f8b8..5e7aa61 100644 --- a/src/GameLogic.gd +++ b/src/GameLogic.gd @@ -3,8 +3,7 @@ extends Node const PlayerScene = preload("res://assets/Player.tscn") var rng = RandomNumberGenerator.new() func _ready(): - $MultiplayerSpawner.add_spawnable_scene("res://assets/Player.tscn") - print($MultiplayerSpawner.get_spawnable_scene(0)) + $PlayerSpawner.add_spawnable_scene("res://assets/Player.tscn") # Start the server if Godot is passed the "--server" argument, # and start a client otherwise. if Globals.is_server: @@ -34,15 +33,13 @@ func create_player(id): #var p = Node3D.new() # Set the name, so players can figure out their local authority - p.name = str(1) + p.name = str(id) print(str(id) + ' just connected') - $NetworkedNodes.add_child(p) + $PlayerSpawner/Players.add_child(p) func destroy_player(id): - pass - # Delete this peer's node. - #$NetworkedNodes.get_node(str(id)).queue_free() + $PlayerSpawner/Players.get_node(str(id)).queue_free() func connected_to_server(): $Pole/Camera3D.queue_free() diff --git a/src/Player.gd b/src/Player.gd index 592d576..3c90b05 100644 --- a/src/Player.gd +++ b/src/Player.gd @@ -2,6 +2,7 @@ extends CharacterBody3D const SPEED = 5.0 const JUMP_VELOCITY = 4.5 +const MOUSE_SENS = 0.002 var synced_position := Vector3.ZERO var synced_rotation := Vector3.ZERO @@ -10,20 +11,31 @@ var synced_rotation := Vector3.ZERO var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") var has_control = false +var mouse_mode = 2 func _ready(): has_control = name == str(multiplayer.get_unique_id()) print( 'I am ' + str(multiplayer.get_unique_id())) - print( 'or ' + str(multiplayer.get_remote_sender_id())) - has_control = !Globals.is_server + #print( 'or ' + str(multiplayer.get_remote_sender_id())) + #has_control = !Globals.is_server if Globals.is_server == false && has_control: - print ( 'Taking control!') - get_node("Camera3D").current = true + print ( 'Taking control of ' + name) + Input.set_mouse_mode(mouse_mode) + $Pivot/Camera.current = true + +func _input(event): + if has_control: + if event is InputEventMouseMotion and mouse_mode == 2: + $Pivot.rotate_y(-event.relative.x*MOUSE_SENS) + $Pivot/Camera.rotate_x(-event.relative.y*MOUSE_SENS) + elif event.is_action_pressed("mode"): + mouse_mode = mouse_mode ^ 2 + Input.set_mouse_mode(mouse_mode) func _physics_process(delta): if not has_control: position = synced_position - rotation = synced_rotation + $Pivot.rotation = synced_rotation return # Add the gravity. if not is_on_floor(): @@ -36,7 +48,7 @@ func _physics_process(delta): # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. var input_dir = Input.get_vector("strafe_left", "strafe_right", "move_forward", "move_backward") - var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + var direction = ($Pivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if direction: velocity.x = direction.x * SPEED velocity.z = direction.z * SPEED @@ -45,19 +57,14 @@ func _physics_process(delta): velocity.z = move_toward(velocity.z, 0, SPEED) move_and_slide() - if Input.is_action_pressed("look_left"): - rotation.y += 0.02 - if Input.is_action_pressed("look_right"): - rotation.y -= 0.02 - rpc_id(1, StringName('update_server'), position, rotation) - #update_server(position, rotation).rpc() + #rpc_id(1, StringName('update_server'), position, rotation) + update_server.rpc(position, $Pivot.rotation) -@rpc("any_peer", "call_remote", "unreliable_ordered") +@rpc("any_peer", "call_local", "unreliable_ordered") func update_server(pos: Vector3, rot: Vector3): - if not multiplayer.is_server(): - return - #if name != str(multiplayer.get_remote_sender_id()): - ##print ("foei?") + #print( 'I am ' + str(multiplayer.get_unique_id())) + if not multiplayer.is_server() or name != str(multiplayer.get_remote_sender_id()): #return + pass synced_position = pos synced_rotation = rot