Once my player enters a portal the player can't jump anymore

My player is supposedly able to jump but after entering a portal they aren’t able to jump anymore.
Here’s my portal code:

  using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
  
    public class PortalTeleporter : MonoBehaviour
    {
        public Transform player;
        public Transform reciever;
  
        private bool playerIsOverlapping = false;
  
        // Update is called once per frame
        void Update () {
            if (playerIsOverlapping)
            {
                Vector3 portalToPlayer = player.position - transform.position;
                float dotProduct = Vector3.Dot(transform.up, portalToPlayer);
  
                // If this is true: The player has moved across the portal
                if (dotProduct < 0f)
                {
                    // Teleport him!
                    float rotationDiff = -Quaternion.Angle(transform.rotation, reciever.rotation);
                    rotationDiff += 180;
                    player.Rotate(Vector3.up, rotationDiff);
  
                    Vector3 positionOffset = Quaternion.Euler(0f, rotationDiff, 0f) * portalToPlayer;
                    player.position = reciever.position + positionOffset;
  
                    playerIsOverlapping = false;
                }
            }
        }
  
        void OnTriggerEnter (Collider other)
        {
            if (other.gameObject.tag == "Player")
            {
                playerIsOverlapping = true;
                print("Collided");
            }
        }
  
        void OnTriggerExit (Collider other)
        {
            if (other.gameObject.tag == "Player")
            {
                playerIsOverlapping = false;
                print("Exited");
            }
        }
  
    }

And here is my jumping code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;
    using UnityEngine.XR.Interaction.Toolkit;
  
    [RequireComponent (typeof (Rigidbody))]
  
    public class Jumping : MonoBehaviour
    {
        [SerializeField] private InputActionReference jumpActionReference;
        [SerializeField] private float jumpForce = 500.0f;
  
        private XRRig _xrRig;
        private CapsuleCollider _collider;
        private Rigidbody _body;
  
        private bool IsGrounded => Physics.Raycast(
            new Vector2(transform.position.x, transform.position.y + 2.0f),
            Vector3.down, 2.0f);
  
        void Start(){
            _body = GetComponent<Rigidbody>();
            _xrRig = GetComponent<XRRig>();
            _collider= GetComponent<CapsuleCollider>();
            jumpActionReference.action.performed += OnJump;
        }
  
        void Update(){
            var center =_xrRig.cameraInRigSpacePos;
            _collider.center = new Vector3(center.x, _collider.center.y, center.z);
            _collider.height = _xrRig.cameraInRigSpaceHeight;
  
        }
  
        private void OnJump(InputAction.CallbackContext obj){
            if (!IsGrounded) return;
            _body.AddForce(Vector3.up * jumpForce);
            print("Jumped");
        }
    }

If your portals exit is at a different height than the entrance, the collider on the XRRig will have the incorrect center.y.

Assuming you want the Y value to be relative to the floor, and always touching the floor, use this in the update function instead:

void Update(){
    var center =_xrRig.cameraInRigSpacePos;
    _collider.height = _xrRig.cameraInRigSpaceHeight;
    _collider.center = new Vector3(center.x, _collider.height.y / 2, center.z);
}

Remember that “_xrRig.cameraInRigSpaceHeight” returns eye height, so you might want to add a little padding (fixed) for the head.

Thank you for your help this worked for me!

1 Like