2024-01-26 00:29:05 +01:00

33 lines
880 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.position = server_position
player.set_character_name(player_name)
if false:
Global.player = player
var controller := PlayerController.new()
controller.character = Global.player
Global.player.add_child(controller)
func spawn_player() -> Player:
var player = player_scene.instantiate()
%Players.add_child(player)
return player