Hello, I am developing a horror game in Unity and I am stuck at one point. I wrote a teleport script to make a loop corridor in my game. This teleport script occurs between 2 cubes. The first cube is where the player will teleport and the 2nd cube will be the player’s trigger object. The only difference between these two cubes is that the trigger cube is rotated 90 degrees compared to the other one. (You can see this in the screenshots.) When the player enters the trigger, since he looks straight at the corridor, he should also look straight where he teleports. But when the player teleports after entering the trigger, he teleports facing the wall (the camera rotation is the same as when entering the trigger). To solve this, I wrote a script to rotate the player 90 degrees in the script, but the player does not turn 90 degrees because the settings in the player’s CinemachineBrain camera are locked. I use a ready-made asset for the FPS Controller. When I open a new project and use Unity’s own controller, the script I wrote works very well. If I switch the CinemachineBrain camera from Smart Update to Manual Update, the player moves forward but the camera stays fixed. How can I solve this problem? I want to rotate my player -90f. You can see the GIF below.
GIFS:
For smooth transition player must be rotate -90f
using UHFPS.Rendering;
using UnityEngine;
using UnityEngine.Rendering;
public class LoFCorridorTrigger : MonoBehaviour
{
public GameObject player;
public Transform playerCamera;
public Transform targetTeleportTrigger;
public Transform currentTrigger;
void OnTriggerEnter(Collider other)
{
if (other.gameObject == player)
{
Vector3 localPositionInTrigger = currentTrigger.InverseTransformPoint(player.transform.position);
Vector3 newWorldPosition = targetTeleportTrigger.TransformPoint(localPositionInTrigger);
player.transform.position = newWorldPosition;
Quaternion localRotationInTrigger = Quaternion.Inverse(currentTrigger.rotation) * playerCamera.rotation;
Quaternion newWorldRotation = targetTeleportTrigger.rotation * localRotationInTrigger;
playerCamera.rotation = newWorldRotation;
player.transform.Rotate(0, -90, 0);
}
}
}