Merged rot and pos sync
This commit is contained in:
@@ -42,13 +42,15 @@ func send_everyone_except(client_id, args):
|
||||
if (str(current_client_id) == str(client_id)): continue
|
||||
if (args.size() == 1): rpc_id(int(current_client_id), args[0])
|
||||
elif (args.size() == 2): rpc_id(int(current_client_id), args[0], args[1])
|
||||
else: rpc_id(int(current_client_id), args[0], args[1], args[2])
|
||||
elif (args.size() == 3): rpc_id(int(current_client_id), args[0], args[1], args[2])
|
||||
else: rpc_id(int(current_client_id), args[0], args[1], args[2], args[3])
|
||||
else:
|
||||
for current_client_id in clients.keys():
|
||||
if (str(current_client_id) == str(client_id)): continue
|
||||
if (args.size() == 1): args[0].rpc_id(int(current_client_id))
|
||||
elif (args.size() == 2): args[0].rpc_id(int(current_client_id), args[1])
|
||||
else: args[0].rpc_id(int(current_client_id), args[1], args[2])
|
||||
elif (args.size() == 3): args[0].rpc_id(int(current_client_id), args[1], args[2])
|
||||
else: args[0].rpc_id(int(current_client_id), args[1], args[2], args[3])
|
||||
|
||||
func _Peer_Connected(client_id):
|
||||
print("User " + str(client_id) + " has conected")
|
||||
@@ -84,12 +86,13 @@ func get_character_properties(client_id):
|
||||
rpc_id(client_id, "set_character_properties", to_send.duplicate())
|
||||
|
||||
@rpc("any_peer", "call_remote", "unreliable")
|
||||
func move_client(client_id, position):
|
||||
func sync_client(client_id, position, rotation):
|
||||
#if(settings["enableAntiCheat"]): if(position > 10): return # нормально допилить надо
|
||||
var client = clients[str(client_id)]
|
||||
var internal_id = client["internal_id"]
|
||||
client["position"] = position
|
||||
send_everyone_except(client_id, [server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").move_puppet, position, internal_id])
|
||||
client["rotation"] = rotation
|
||||
send_everyone_except(client_id, [server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").sync_puppet, internal_id, position, rotation])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
func get_client_list(client_id):
|
||||
@@ -104,12 +107,12 @@ func get_server_settings(client_id):
|
||||
var internal_id = client["internal_id"]
|
||||
server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").set_game_settings.rpc_id(int(client_id), settings["game"])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "unreliable")
|
||||
func rotate_camera_client(client_id, head_y, camera_x):
|
||||
var client = clients[str(client_id)]
|
||||
var internal_id = client["internal_id"]
|
||||
client["rotation"] = {"x": camera_x, "y": head_y}
|
||||
send_everyone_except(client_id, [server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").rotate_camera_puppet, client["rotation"] , internal_id])
|
||||
#@rpc ("any_peer", "call_remote", "unreliable")
|
||||
#func rotate_camera_client(client_id, head_y, camera_x):
|
||||
#var client = clients[str(client_id)]
|
||||
#var internal_id = client["internal_id"]
|
||||
#client["rotation"] = {"x": camera_x, "y": head_y}
|
||||
#send_everyone_except(client_id, [server_map.get_node("player" + str(internal_id)).find_child("CharacterBody3D").rotate_camera_puppet, client["rotation"] , internal_id])
|
||||
|
||||
##########################################CLIENT#######################
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func _unhandled_input(event):
|
||||
head.rotate_y(-event.relative.x * SENSETIVITY)
|
||||
camera.rotate_x(-event.relative.y * SENSETIVITY)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60))
|
||||
Networking.rotate_camera_client.rpc_id(1, multiplayer.get_unique_id(), head.rotation.y, camera.rotation.x)
|
||||
#Networking.rotate_camera_client.rpc_id(1, multiplayer.get_unique_id(), head.rotation.y, camera.rotation.x)
|
||||
|
||||
func _physics_process(delta):
|
||||
if (!properties["is_playable"]): return
|
||||
@@ -91,13 +91,15 @@ func _physics_process(delta):
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta)
|
||||
move_and_slide()
|
||||
if (!multiplayer.is_server()):
|
||||
Networking.move_client.rpc_id(1, multiplayer.get_unique_id(), $".".position)
|
||||
Networking.sync_client.rpc_id(1, multiplayer.get_unique_id(), $".".position, { "y": head.rotation.y, "x": camera.rotation.x})
|
||||
#print("I am " + $"..".name +", belonging of " + str(multiplayer.get_unique_id()) + ", with internal ID: " + str(properties["internal_id"]))
|
||||
|
||||
@rpc ("authority", "call_remote", "unreliable")
|
||||
func move_puppet(p: Vector3, i_id):
|
||||
func sync_puppet(i_id, p, rot):
|
||||
if (i_id == properties["internal_id"]):
|
||||
playerCharacterBody.position = p
|
||||
head.rotation.y = rot.y
|
||||
camera.rotation.x = rot.x
|
||||
|
||||
@rpc ("authority", "call_remote", "reliable")
|
||||
func set_game_settings(s):
|
||||
@@ -109,8 +111,7 @@ func set_game_settings(s):
|
||||
run = game_settings["moving"]["run"]
|
||||
jump = game_settings["moving"]["jump"]
|
||||
|
||||
@rpc("authority", "call_remote", "unreliable")
|
||||
func rotate_camera_puppet(rot, i_id):
|
||||
if (i_id == properties["internal_id"]):
|
||||
head.rotation.y = rot.y
|
||||
camera.rotation.x = rot.x
|
||||
#@rpc("authority", "call_remote", "unreliable")
|
||||
#func rotate_camera_puppet(rot, i_id):
|
||||
#if (i_id == properties["internal_id"]):
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user