Exemplo n.º 1
0
        public void Predict(ushort playerEntityId, InputMessageModel inputMessageModel, float physicsSimulationDuration)
        {
            //взять ввод игрока
            if (inputMessageModel == null)
            {
                log.Debug("Нет ввода");
                return;
            }

            if (physicsSimulationDuration < 0.005f)
            {
                log.Debug("Что за космический fps?");
            }

            // log.Debug("Тик физики "+physicsSimulationDuration);
            //линейное движение игрока
            ServerGameEntity playerEntity     = gameContext.GetEntityWithId(playerEntityId);
            Rigidbody        warshipRigidbody = playerEntity.rigidbody.value;
            Vector3          inputVector      = inputMessageModel.GetVector3();
            float            maxSpeed         = 10f;

            warshipRigidbody.velocity = Vector3.zero;

            if (inputVector.sqrMagnitude > 0.001f)
            {
                // log.Debug("Линейное движение игрока");
                physicsVelocityManager.ApplyVelocity(warshipRigidbody, inputVector, maxSpeed);
            }

            //вращательное движение игрока
            if (!float.IsNaN(inputMessageModel.Angle))
            {
                float angularVelocity = 90;
                physicsRotationManager.ApplyRotation(playerEntity.rigidbody.value, inputMessageModel.Angle,
                                                     angularVelocity, physicsSimulationDuration);
            }

            //todo спавн пуль игрока
            //todo движение пуль игрока

            //симуляция физики
            scene.GetPhysicsScene().Simulate(physicsSimulationDuration);
        }