Implement basic networking

This commit is contained in:
Aslan 2026-01-29 09:43:15 -05:00
parent c320d9ddcb
commit 994823a9c3
25 changed files with 643 additions and 217 deletions

View file

@ -4,6 +4,39 @@ public class Character(Sector sector, Vector3 localCoordinates) : GameObject(sec
{
private Player player;
public bool SheduledUpdateNode = false;
public override void AssignSector(Sector sector)
{
CurrentSector = sector;
ResetLocalCoordinates();
UpdateSectorOffsetToMainPlayer();
UpdateNodePosition();
if (IsMainPlayer())
{
GameManager.Singleton.ApplyOrigin();
if (!Global.IsGameHost)
{
GameManager.Singleton.RpcId(
1,
nameof(GameManager.Singleton.RpcSendNearbySectors),
CurrentSector.Coordinates,
NetworkManager.Singleton.LocalNetId
);
}
}
reassigning = false;
}
public bool IsMainPlayer()
{
return player == GameManager.Singleton.MainPlayer;
}
public Player InstantiatePlayer()
{
PackedScene prefab = ResourceLoader.Load<PackedScene>("res://prefabs/gameObjects/player.tscn");
@ -17,6 +50,13 @@ public class Character(Sector sector, Vector3 localCoordinates) : GameObject(sec
public override void UpdateNodePosition()
{
player.GlobalPosition = LocalCoordinates;
if (IsMainPlayer())
{
player.GlobalPosition = LocalCoordinates;
}
else
{
player.GlobalPosition = LocalCoordinates + SectorOffset;
}
}
}