33 lines
880 B
GDScript3
Raw Normal View History

2024-01-24 19:57:31 +00:00
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
2024-01-25 23:29:05 +00:00
player.set_character_name(player_name)
if false:
Global.player = player
var controller := PlayerController.new()
controller.character = Global.player
Global.player.add_child(controller)
2024-01-24 19:57:31 +00:00
func spawn_player() -> Player:
var player = player_scene.instantiate()
%Players.add_child(player)
return player