public async Task PositionHandler(PositionUpdatePacket packet, IRakConnection connection)
        {
            var player = Server.FindPlayer(connection);

            if (player?.Transform == default)
            {
                Logger.Warning($"{connection} is not logged in but sent a Position Update packet.");
                return;
            }

            //
            // The server is a slave to the position update packets it gets from the client right now.
            //

            player.Transform.Position = packet.Position;
            player.Transform.Rotation = packet.Rotation;

            var physics = player.GetComponent <ControllablePhysicsComponent>();

            physics.HasPosition = true;

            physics.IsOnGround = packet.IsOnGround;
            physics.NegativeAngularVelocity = packet.NegativeAngularVelocity;

            physics.HasVelocity = packet.HasVelocity;

            physics.Velocity = packet.Velocity;

            physics.HasAngularVelocity = packet.HasAngularVelocity;

            physics.AngularVelocity = packet.AngularVelocity;

            physics.Platform = default; //player.Zone.GameObjects.FirstOrDefault(g => g.ObjectId == packet.PlatformObjectId);

            physics.PlatformPosition = packet.PlatformPosition;

            Zone.SendSerialization(player, player.Zone.Players.Where(
                                       p => p != player
                                       ).ToArray());

            player.UpdateView();

            await player.OnPositionUpdate.InvokeAsync(packet.Position, packet.Rotation);
        }
Exemple #2
0
        public async Task PositionHandler(PositionUpdatePacket packet, IRakConnection connection)
        {
            var player = UchuServer.FindPlayer(connection);

            if (player?.Transform == default)
            {
                return;
            }

            // The server is a slave to the position update packets it gets from the client right now.
            player.Transform.Position = packet.Position;
            player.Transform.Rotation = packet.Rotation;

            var physics = player.GetComponent <ControllablePhysicsComponent>();

            physics.HasPosition = true;

            physics.IsOnGround = packet.IsOnGround;
            physics.NegativeAngularVelocity = packet.NegativeAngularVelocity;

            physics.HasVelocity = (packet.Velocity != Vector3.Zero);

            physics.Velocity = packet.Velocity;

            physics.HasAngularVelocity = (packet.AngularVelocity != Vector3.Zero);

            physics.AngularVelocity = packet.AngularVelocity;

            physics.Platform = packet.PlatformObjectId;

            physics.PlatformPosition = packet.PlatformPosition;

            Zone.SendSerialization(player, player.Zone.Players.Where(
                                       p => p != player
                                       ).ToArray());

            player.UpdateView();

            await player.OnPositionUpdate.InvokeAsync(packet.Position, packet.Rotation);
        }