0
votes

I am trying (for learning purposes) to make a Portal game. I have the basics working, I can place two portals, and walking within the collider of one makes me teleport to the other, however I can't seem to get the facing direction/rotation to work. I want to face outwards from the new portal after the teleportation.

I have tried the following, with no success: var angle = thisPortalCamera.transform.rotation.eulerAngles.y - otherPortalCamera.transform.rotation.eulerAngles.y; playerChar.transform.Rotate(Vector3.up, angle);

My idea here was that only the y-axis rotation really matters, and I think I should rotate the player by the difference in axis between the two portals. This is probably really simple and easy, but I am pretty new to Unity. Any suggestions?

2

2 Answers

0
votes

The easiest way would be to set your portal so that its forward is the orientation you want you player to have. Then you just go with:

player.transform.rotation = portal.transform.rotation;
player.transform.position = portal.transform.position;

The aim is to have the blue arrow of your portal to point in the right direction.

0
votes

One of the easiest way is to use the function LookAt() and Rotate() of the transform. This function take one parameter that is the Position the object has to look.

transform.LookAt(portal.position);
tranform.Rotate(new Vector3(0,180,0);

This will make your character face the opposite way of your portal.