29 lines
782 B
GDScript3
29 lines
782 B
GDScript3
|
extends PacketHandler
|
||
|
|
||
|
@export var player_scene: PackedScene
|
||
|
|
||
|
func _ready():
|
||
|
assert(player_scene)
|
||
|
%Client.set_handler(Packet.PLAYER_STATE, self)
|
||
|
|
||
|
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
|