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;
        }
Example #2
0
        protected virtual void FixedUpdate()
        {
            smoothYaw.FixedUpdate();
            smoothPitch.FixedUpdate();

            smoothPosition.FixedUpdate();
            smoothVelocity.FixedUpdate();
            rigidbody.velocity = MovementHelper.GetCorrectedVelocity(smoothPosition.SmoothValue, smoothVelocity.SmoothValue, gameObject, PlayerMovement.BROADCAST_INTERVAL);
            smoothRotation.FixedUpdate();
            smoothAngularVelocity.FixedUpdate();
            rigidbody.angularVelocity = MovementHelper.GetCorrectedAngularVelocity(smoothRotation.SmoothValue, smoothAngularVelocity.SmoothValue, gameObject, PlayerMovement.BROADCAST_INTERVAL);
        }
        protected virtual void FixedUpdate()
        {
            SmoothYaw.FixedUpdate();
            SmoothPitch.FixedUpdate();

            SmoothPosition.FixedUpdate();
            SmoothVelocity.FixedUpdate();
            rigidbody.isKinematic = false; // we should maybe find a way to remove UWE's FreezeRigidBodyWhenFar component...tried removing it but caused a bunch of issues.
            rigidbody.velocity    = MovementHelper.GetCorrectedVelocity(SmoothPosition.SmoothValue, SmoothVelocity.SmoothValue, gameObject, PlayerMovement.BROADCAST_INTERVAL);
            SmoothRotation.FixedUpdate();
            SmoothAngularVelocity.FixedUpdate();
            rigidbody.angularVelocity = MovementHelper.GetCorrectedAngularVelocity(SmoothRotation.SmoothValue, SmoothAngularVelocity.SmoothValue, gameObject, PlayerMovement.BROADCAST_INTERVAL);
        }
Example #4
0
        public void FixedUpdate()
        {
            if (swimBehaviour)
            {
                return;
            }

            smoothPosition.FixedUpdate();
            smoothRotation.FixedUpdate();

            rigidbody.isKinematic     = false;
            rigidbody.velocity        = MovementHelper.GetCorrectedVelocity(smoothPosition.Current, Vector3.zero, gameObject, EntityPositionBroadcaster.BROADCAST_INTERVAL);
            rigidbody.angularVelocity = MovementHelper.GetCorrectedAngularVelocity(smoothRotation.Current, Vector3.zero, gameObject, EntityPositionBroadcaster.BROADCAST_INTERVAL);
        }