WIP: Some updates
This commit is contained in:
@ -119,7 +119,7 @@ func _process(delta: float) -> void:
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func verify_position() -> void:
|
||||
var desired_position: Vector3 = shared_node.global_position
|
||||
controlled_node.send_position.rpc_id(1, desired_position.x, desired_position.y, desired_position.z)
|
||||
controlled_node.send_position.rpc_id(1, desired_position)
|
||||
|
||||
@rpc("authority", "call_local")
|
||||
func adjust_position(x: float, y: float, z: float):
|
||||
|
@ -2,13 +2,13 @@ extends Node3D
|
||||
class_name ServerNode
|
||||
|
||||
var jumping := false
|
||||
var input_direction: Vector2
|
||||
var player_node: PlayerNode
|
||||
|
||||
# TODO: Shoould not be defined here
|
||||
const DEFAULT_WEAPON := "ak"
|
||||
var first_slot_weapon: WeaponController
|
||||
|
||||
@export var input_direction: Vector2
|
||||
@export var owner_id: int = 0
|
||||
|
||||
@onready var camera_mount: Node3D = $SharedNode/CameraMount
|
||||
@ -59,9 +59,12 @@ func _physics_process(delta: float) -> void:
|
||||
shared_node.velocity.z = move_toward(shared_node.velocity.z, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
else:
|
||||
print(str(name) + str(shared_node.velocity))
|
||||
|
||||
shared_node.move_and_slide()
|
||||
if multiplayer.is_server():
|
||||
shared_node.move_and_slide()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not multiplayer.is_server():
|
||||
shared_node.move_and_slide()
|
||||
@rpc("any_peer", "call_local", "unreliable")
|
||||
func jump():
|
||||
jumping = true
|
||||
@ -93,6 +96,10 @@ func _on_reconciliation_timer_timeout() -> void:
|
||||
func _veryfy_position_and_rotation() -> void:
|
||||
player_node.verify_position()
|
||||
player_node.verify_rotation()
|
||||
|
||||
#@rpc("authority", "call_remote", "unreliable")
|
||||
#func _sync_transorm():
|
||||
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func _adjust_position(x: float, y: float, z: float) -> void:
|
||||
@ -103,21 +110,19 @@ func _adjust_rotation(x: float, y: float, z: float) -> void:
|
||||
player_node.adjust_rotation(x, y, z)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func send_position(x: float, y: float, z: float):
|
||||
func send_position(desired_position: Vector3):
|
||||
if multiplayer.is_server():
|
||||
var desired_position: Vector3 = Vector3(x, y, z)
|
||||
if multiplayer.is_server():
|
||||
var real_position: Vector3 = shared_node.global_position
|
||||
var difference: Vector3 = desired_position - real_position
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.2, 0.2, 0.2)):
|
||||
shared_node.global_position = desired_position
|
||||
elif is_vector_a_lower_than_b(difference, Vector3(0.4, 0.4, 0.4)):
|
||||
var new_position: Vector3 = desired_position.lerp(real_position, 0.5)
|
||||
push_warning("player position is not valid, lerping")
|
||||
_adjust_position.rpc_id(owner_id, new_position.x, new_position.y, new_position.z)
|
||||
else:
|
||||
push_warning("player position is not valid, adjusting")
|
||||
_adjust_position.rpc_id(owner_id, real_position.x, real_position.y, real_position.z)
|
||||
var real_position: Vector3 = shared_node.global_position
|
||||
var difference: Vector3 = desired_position - real_position
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.2, 0.2, 0.2)):
|
||||
shared_node.global_position = desired_position
|
||||
elif is_vector_a_lower_than_b(difference, Vector3(0.4, 0.4, 0.4)):
|
||||
var new_position: Vector3 = desired_position.lerp(real_position, 0.5)
|
||||
push_warning("player position is not valid, lerping")
|
||||
_adjust_position.rpc_id(owner_id, new_position.x, new_position.y, new_position.z)
|
||||
else:
|
||||
push_warning("player position is not valid, adjusting")
|
||||
_adjust_position.rpc_id(owner_id, real_position.x, real_position.y, real_position.z)
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func send_rotation(x: float, y: float, z: float):
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_2dhi2"]
|
||||
properties/0/path = NodePath("SharedNode:position")
|
||||
properties/0/spawn = true
|
||||
properties/0/spawn = false
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath("SharedNode:rotation")
|
||||
properties/1/spawn = true
|
||||
@ -14,6 +14,9 @@ properties/1/replication_mode = 1
|
||||
properties/2/path = NodePath(".:owner_id")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 1
|
||||
properties/3/path = NodePath(".:input_direction")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 1
|
||||
|
||||
[node name="ServerNode" type="Node3D"]
|
||||
script = ExtResource("1_bau14")
|
||||
|
Reference in New Issue
Block a user