Пример #1
0
        public override void Process(VehicleMovement vehicleMovement)
        {
            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(vehicleMovement.Guid);

            RemotePlayer player = remotePlayerManager.FindOrCreate(vehicleMovement.PlayerId);

            Vector3    remotePosition  = vehicleMovement.Position;
            Vector3    remoteVelocity  = vehicleMovement.Velocity;
            Quaternion remoteRotation  = vehicleMovement.BodyRotation;
            Vector3    angularVelocity = vehicleMovement.AngularVelocity;

            Vehicle vehicle = null;
            SubRoot subRoot = null;

            if (opGameObject.IsPresent())
            {
                GameObject gameObject = opGameObject.Get();

                vehicle = gameObject.GetComponent <Vehicle>();
                subRoot = gameObject.GetComponent <SubRoot>();

                MultiplayerVehicleControl mvc = null;

                if (subRoot != null)
                {
                    mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>();
                }
                else if (vehicle != null)
                {
                    var seamoth = vehicle as SeaMoth;
                    var exosuit = vehicle as Exosuit;

                    if (seamoth)
                    {
                        mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>();
                    }
                    else if (exosuit)
                    {
                        mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>();
                    }
                }

                if (mvc != null)
                {
                    mvc.SetPositionVelocityRotation(remotePosition, remoteVelocity, remoteRotation, angularVelocity);
                    mvc.SetThrottle(vehicleMovement.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleMovement.SteeringWheelYaw, vehicleMovement.SteeringWheelPitch);
                }
            }
            else
            {
                CreateVehicleAt(player, vehicleMovement.TechType, vehicleMovement.Guid, remotePosition, remoteRotation);
            }
            player.SetVehicle(vehicle);
            player.SetSubRoot(subRoot);
            player.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>());

            player.animationController.UpdatePlayerAnimations = false;
        }
        public override void Process(VehicleMovement vehicleMovement)
        {
            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(vehicleMovement.Guid);

            RemotePlayer player = remotePlayerManager.FindOrCreate(vehicleMovement.PlayerId);

            Vector3    remotePosition = ApiHelper.Vector3(vehicleMovement.Position);
            Vector3    remoteVelocity = ApiHelper.Vector3(vehicleMovement.Velocity);
            Quaternion remoteRotation = ApiHelper.Quaternion(vehicleMovement.BodyRotation);

            Vehicle vehicle = null;
            SubRoot subRoot = null;

            if (opGameObject.IsPresent())
            {
                GameObject gameObject = opGameObject.Get();

                Rigidbody rigidbody = gameObject.GetComponent <Rigidbody>();

                if (rigidbody != null)
                {
                    //todo: maybe toggle kinematic if jumping large distances?

                    /*
                     * For the cyclops, it is too intense for the game to lerp the entire structure every movement
                     * packet update.  Instead, we try to match the velocity.  Due to floating points not being
                     * precise, this will skew quickly.  To counter this, we apply micro adjustments each packet
                     * to get the simulation back in sync.  The adjustments will increase in size the larger the
                     * out of sync issue is.
                     *
                     * Besides, this causes the movement of the Cyclops, vehicles and player to be very fluid.
                     */

                    rigidbody.velocity        = MovementHelper.GetCorrectedVelocity(remotePosition, remoteVelocity, gameObject, PlayerMovement.BROADCAST_INTERVAL);
                    rigidbody.angularVelocity = MovementHelper.GetCorrectedAngularVelocity(remoteRotation, gameObject, PlayerMovement.BROADCAST_INTERVAL);
                }
                else
                {
                    Console.WriteLine("Vehicle did not have a rigidbody!");
                }

                vehicle = gameObject.GetComponent <Vehicle>();
                subRoot = gameObject.GetComponent <SubRoot>();
            }
            else
            {
                CreateVehicleAt(player, vehicleMovement.TechType, vehicleMovement.Guid, remotePosition, remoteRotation);
            }
            player.SetVehicle(vehicle);
            player.SetSubRoot(subRoot);
            player.SetPilotingChair(subRoot.GetComponentInChildren <PilotingChair>());

            player.animationController.UpdatePlayerAnimations = false;
        }