werkende multiplayer. soort van
This commit is contained in:
+7
-6
@@ -6,21 +6,22 @@
|
|||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_gojcw"]
|
[sub_resource type="Animation" id="Animation_gojcw"]
|
||||||
resource_name = "new_animation"
|
resource_name = "new_animation"
|
||||||
length = 30.0
|
length = 35.0
|
||||||
|
loop_mode = 1
|
||||||
tracks/0/type = "position_3d"
|
tracks/0/type = "position_3d"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath(".")
|
tracks/0/path = NodePath(".")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 2
|
||||||
tracks/0/loop_wrap = true
|
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/type = "rotation_3d"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath(".")
|
tracks/1/path = NodePath(".")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
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"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_53h31"]
|
||||||
_data = {
|
_data = {
|
||||||
@@ -37,10 +38,10 @@ root_node = NodePath("../Camera3D")
|
|||||||
libraries = {
|
libraries = {
|
||||||
"": SubResource("AnimationLibrary_53h31")
|
"": SubResource("AnimationLibrary_53h31")
|
||||||
}
|
}
|
||||||
speed_scale = 0.1
|
speed_scale = 0.5
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="."]
|
[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="."]
|
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||||
environment = ExtResource("2_stw21")
|
environment = ExtResource("2_stw21")
|
||||||
|
|||||||
+8
-5
@@ -11,13 +11,16 @@ size = Vector3(0.4, 1.8, 0.4)
|
|||||||
[node name="Player" type="CharacterBody3D"]
|
[node name="Player" type="CharacterBody3D"]
|
||||||
script = ExtResource("1_la1lv")
|
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="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.899966, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.899966, 0)
|
||||||
shape = SubResource("ConvexPolygonShape3D_5mrtf")
|
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")
|
mesh = SubResource("PrismMesh_c7ovg")
|
||||||
skeleton = NodePath("../..")
|
skeleton = NodePath("../../..")
|
||||||
|
|||||||
@@ -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"]
|
[node name="Node3D" type="Node3D"]
|
||||||
script = ExtResource("1_0vmht")
|
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="."]
|
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||||
environment = ExtResource("3_8gl6a")
|
environment = ExtResource("3_8gl6a")
|
||||||
|
|
||||||
@@ -68,8 +65,16 @@ fov = 96.3
|
|||||||
near = 1.0
|
near = 1.0
|
||||||
far = 300.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="."]
|
[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="."]
|
[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)
|
transform = Transform3D(1, 0, 0, 0, -0.999, 0.0447004, 0, -0.0447004, -0.999, 0, 14.0621, -6.13505)
|
||||||
|
|||||||
@@ -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)
|
"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)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
+4
-7
@@ -3,8 +3,7 @@ extends Node
|
|||||||
const PlayerScene = preload("res://assets/Player.tscn")
|
const PlayerScene = preload("res://assets/Player.tscn")
|
||||||
var rng = RandomNumberGenerator.new()
|
var rng = RandomNumberGenerator.new()
|
||||||
func _ready():
|
func _ready():
|
||||||
$MultiplayerSpawner.add_spawnable_scene("res://assets/Player.tscn")
|
$PlayerSpawner.add_spawnable_scene("res://assets/Player.tscn")
|
||||||
print($MultiplayerSpawner.get_spawnable_scene(0))
|
|
||||||
# Start the server if Godot is passed the "--server" argument,
|
# Start the server if Godot is passed the "--server" argument,
|
||||||
# and start a client otherwise.
|
# and start a client otherwise.
|
||||||
if Globals.is_server:
|
if Globals.is_server:
|
||||||
@@ -34,15 +33,13 @@ func create_player(id):
|
|||||||
#var p = Node3D.new()
|
#var p = Node3D.new()
|
||||||
|
|
||||||
# Set the name, so players can figure out their local authority
|
# Set the name, so players can figure out their local authority
|
||||||
p.name = str(1)
|
p.name = str(id)
|
||||||
print(str(id) + ' just connected')
|
print(str(id) + ' just connected')
|
||||||
|
|
||||||
$NetworkedNodes.add_child(p)
|
$PlayerSpawner/Players.add_child(p)
|
||||||
|
|
||||||
func destroy_player(id):
|
func destroy_player(id):
|
||||||
pass
|
$PlayerSpawner/Players.get_node(str(id)).queue_free()
|
||||||
# Delete this peer's node.
|
|
||||||
#$NetworkedNodes.get_node(str(id)).queue_free()
|
|
||||||
|
|
||||||
func connected_to_server():
|
func connected_to_server():
|
||||||
$Pole/Camera3D.queue_free()
|
$Pole/Camera3D.queue_free()
|
||||||
|
|||||||
+24
-17
@@ -2,6 +2,7 @@ extends CharacterBody3D
|
|||||||
|
|
||||||
const SPEED = 5.0
|
const SPEED = 5.0
|
||||||
const JUMP_VELOCITY = 4.5
|
const JUMP_VELOCITY = 4.5
|
||||||
|
const MOUSE_SENS = 0.002
|
||||||
|
|
||||||
var synced_position := Vector3.ZERO
|
var synced_position := Vector3.ZERO
|
||||||
var synced_rotation := 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 gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||||
|
|
||||||
var has_control = false
|
var has_control = false
|
||||||
|
var mouse_mode = 2
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
has_control = name == str(multiplayer.get_unique_id())
|
has_control = name == str(multiplayer.get_unique_id())
|
||||||
print( 'I am ' + str(multiplayer.get_unique_id()))
|
print( 'I am ' + str(multiplayer.get_unique_id()))
|
||||||
print( 'or ' + str(multiplayer.get_remote_sender_id()))
|
#print( 'or ' + str(multiplayer.get_remote_sender_id()))
|
||||||
has_control = !Globals.is_server
|
#has_control = !Globals.is_server
|
||||||
if Globals.is_server == false && has_control:
|
if Globals.is_server == false && has_control:
|
||||||
print ( 'Taking control!')
|
print ( 'Taking control of ' + name)
|
||||||
get_node("Camera3D").current = true
|
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):
|
func _physics_process(delta):
|
||||||
if not has_control:
|
if not has_control:
|
||||||
position = synced_position
|
position = synced_position
|
||||||
rotation = synced_rotation
|
$Pivot.rotation = synced_rotation
|
||||||
return
|
return
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
@@ -36,7 +48,7 @@ func _physics_process(delta):
|
|||||||
# Get the input direction and handle the movement/deceleration.
|
# Get the input direction and handle the movement/deceleration.
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
# 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 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:
|
if direction:
|
||||||
velocity.x = direction.x * SPEED
|
velocity.x = direction.x * SPEED
|
||||||
velocity.z = direction.z * SPEED
|
velocity.z = direction.z * SPEED
|
||||||
@@ -45,19 +57,14 @@ func _physics_process(delta):
|
|||||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
if Input.is_action_pressed("look_left"):
|
#rpc_id(1, StringName('update_server'), position, rotation)
|
||||||
rotation.y += 0.02
|
update_server.rpc(position, $Pivot.rotation)
|
||||||
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("any_peer", "call_remote", "unreliable_ordered")
|
@rpc("any_peer", "call_local", "unreliable_ordered")
|
||||||
func update_server(pos: Vector3, rot: Vector3):
|
func update_server(pos: Vector3, rot: Vector3):
|
||||||
if not multiplayer.is_server():
|
#print( 'I am ' + str(multiplayer.get_unique_id()))
|
||||||
return
|
if not multiplayer.is_server() or name != str(multiplayer.get_remote_sender_id()):
|
||||||
#if name != str(multiplayer.get_remote_sender_id()):
|
|
||||||
##print ("foei?")
|
|
||||||
#return
|
#return
|
||||||
|
pass
|
||||||
synced_position = pos
|
synced_position = pos
|
||||||
synced_rotation = rot
|
synced_rotation = rot
|
||||||
|
|||||||
Reference in New Issue
Block a user