Question by
thezoeyteh · Jul 30, 2021 at 11:31 AM ·
vrjumpportal
Once my player enters a portal the player can't jump anymore,Once my player enters a portal the player can't jump
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");
}
}
Comment