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