Can someone help me figure out what's wrong with my portal script?

I’m doing a bunch of environment prefabs for an FPS and I’m currently stuck on making a portal system.

I already have a teleporter, so this needs to be different.

To elaborate a teleporter sends the player to a location, that does not return to the teleporter, and zeroes the player’s linear velocity while changing the view so its facing the correct way. I also gave it the option to give the player new velocities.

A PORTAL on the other hand is what portals in Portal (the game) does. Two points that the player enters into one, then comes out the other with relative facing and velocity. put one on the ground and the other on a wall, then jump off a high area into the portal on the ground results in you flying out of the portal on the wall.

Make sense?

I’m aiming to make something that looks like what they would have done in the 90’s and hardly looking for perfection.

Right now the entrance is a sphere trigger halfway in a surface, with a cube on the backside that deactivates it when touched so you dont go through it if the sphere is poking through the backside. Then there is an empty that I use as the exit.

It works somewhat, but the direction and the velocity keep messing up.

Any suggestions?

(This goes on the enterance)

using Unity.Cinemachine;
using UnityEngine;

public class PortalEntrance : MonoBehaviour
{
    public Transform destination, otherPortal;
    public bool active = true;

    private void OnTriggerEnter(Collider other)
    {
        if (active)
        {
            Transform player = other.transform.parent;
            CinemachinePanTilt panTilt = player.GetComponentInChildren<CinemachinePanTilt>();
            Rigidbody targetRB = other.GetComponentInParent<Rigidbody>();
            targetRB.position = destination.position;
            targetRB.linearVelocity = Quaternion.Euler(destination.eulerAngles) * targetRB.linearVelocity;
            panTilt.PanAxis.Value += destination.eulerAngles.y;
            panTilt.TiltAxis.Value += destination.eulerAngles.z;
            otherPortal.GetComponent<PortalEntrance>().active = false;
        }
    }
    private void OnTriggerExit(Collider other)
    {
        active = true;
    }
}

(This goes on the cube that stops the player from going in backwards)

using UnityEngine;

public class PortalCancelTrigger : MonoBehaviour
{
    public Transform portal;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter(Collider other)
    {
        portal.gameObject.SetActive(false);
    }

    private void OnTriggerExit(Collider other)
    {
        portal.gameObject.SetActive(true);
    }
}

Thanks

Can you show your CinemachinePanTilt inspector?
Also, can you say something more about what gets messed up and how? Maybe show a video?

Well, I got it SORT OF working, but I’m realizing it’s nothing that I can practically use and my efforts are best spent elsewhere.

The problem seems to be that cimemachine’s camera is rotated 90 degrees from what other vectors are. So if I need to shift velocity 45 degrees, then cinamachine need to rotate 135.

There’s other issues, especially at high speed, and I’m thinking “this is a novelty at best and it’s not going to impress anyone nor will they care. More likely annoy them. I’m just sinking in potentially 20 hours that could be better spent on a level or enemy.”

So I’m cutting it, for now.

Thanks though.