Example #1
0
        /// <summary>
        /// Sit in current vehicle.
        /// </summary>
        private void SitInCurrentVehicle()
        {
            if (currentVehicle != null)
            {
                // Make sure player character is attached as we will not update it's position until he leaves vehicle.

                if (IsSpawned)
                {
                    Game.Objects.GameVehicle vehicleGameObject = currentVehicle.GameObject;
                    Transform seatTransform = vehicleGameObject.SeatTransform;
                    Teleport(seatTransform.position, seatTransform.rotation);

                    characterGameObject.transform.SetParent(vehicleGameObject.VehicleTransform, false);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Leave vehicle player is currently sitting in.
        /// </summary>
        public virtual void LeaveVehicle()
        {
            Client.Assert(currentVehicle != null && state != State.OnFoot, "Player is leaving vehicle but he is not in vehicle.");

            // Detach character game object from vehicle.

            if (IsSpawned)
            {
                characterGameObject.transform.SetParent(null);

                Game.Objects.GameVehicle vehicleGameObject = currentVehicle.GameObject;
                Transform seatTransform = vehicleGameObject.SeatTransform;
                Teleport(seatTransform.position, seatTransform.rotation);
            }

            // Notify vehicle that the player left.

            currentVehicle.ClearPlayer(state == State.Passenger);
            currentVehicle = null;

            // Set state of the player.

            SwitchState(State.OnFoot);
        }