2024-01-25 12:10:29 +01:00

28 lines
734 B
GDScript

extends PacketHandler
@export var player_scene: PackedScene
func _ready():
assert(player_scene)
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
var player_name := data.get_string_from_utf8()
print(player_name)
var position_data := data.slice(player_name.length() + 1)
var server_position := Vector3()
server_position.x = position_data.decode_float(0)
server_position.y = position_data.decode_float(4)
server_position.z = position_data.decode_float(8)
print(server_position)
var player := spawn_player()
player.name = player_name
player.position = server_position
Global.player = player
func spawn_player() -> Player:
var player = player_scene.instantiate()
%Players.add_child(player)
return player