I’m making a game similar to Portal and already done the teleporter. But when the Player or other object enter on the first portal and is teleported to de other portal, he keeps the same trajectory. I wish the trajectory of the object changes based on the position of the portal. Ex: If Player or other object enter in a vertical Portal, but the other portal is in horizontal position, the Player is launched up.
This is what I’ve already did.
using UnityEngine;
using System.Collections;
public class ObjetoPortalavel : MonoBehaviour {
public GameObject ThisObject;
public GameObject Portal1;
public GameObject Portal2;
void OnCollisionEnter2D(Collision2D collision)
{
Portal1.GetComponent<Collider2D>().enabled = true;
Portal2.GetComponent<Collider2D>().enabled = true;
if (collision.gameObject.tag == "Portal1")
{
ThisObject.transform.position = Portal2.transform.position;
ThisObject.transform.eulerAngles = Portal2.transform.eulerAngles;
Portal2.GetComponent<Collider2D>().enabled = false;
}
if (collision.gameObject.tag == "Portal2")
{
ThisObject.transform.position = Portal1.transform.position;
ThisObject.transform.eulerAngles = Portal1.transform.eulerAngles;
Portal1.GetComponent<Collider2D>().enabled = false;
}
}
// Update is called once per frame
void Update () {
Portal1.gameObject.tag = "Portal1";
Portal2.gameObject.tag = "Portal2";
}
}
Sorry for all the confusion, I'm a tad new to unity. I have set up a scene like the image, and I'd like to project a vector on the plane using the two rays that are being cast on it by the boxes. So what I know is projectedVector = Vector3.ProjectOnPlane(a, rayB.normal); But I don't know what to put in "a".
– ShawnAlberts