Hi!
A little background:
I have asked this question before and i thought it worked but now it doesn’t work on some situation.
I want to teleport my player to another place when he enters the portal and rotate him to thew portals exit.
So when my exit portal is on the ground the player exits and is turning upwards(z = 270)!
Code:
using UnityEngine;
using System.Collections;
public class StepThroughPortal : MonoBehaviour
{
public GameObject otherPortal;
public GameObject player;
Quaternion rotate;
void Start()
{
//rotate = Quaternion.LookRotation(otherPortal.transform.forward);
}
void Update()
{
}
public void Interact(Transform collidedObject)
{
Debug.Log("something hit the portal");
collidedObject.position = otherPortal.transform.position + otherPortal.transform.forward;
collidedObject.rotation = Quaternion.LookRotation(otherPortal.transform.forward);
TrackVelocity velocityScript = collidedObject.GetComponent<TrackVelocity>();
if (velocityScript != null)
collidedObject.GetComponent<Rigidbody>().velocity = Quaternion.FromToRotation(transform.forward, -otherPortal.transform.forward) * velocityScript.Velocity;
}
void OnCollisionEnter(Collision collidedObject)
{
Interact (collidedObject.transform);
}
}
Special request for help: @dhore who have helped me in the previous question greatly!
Thanks in advance.
Ethan