CinemachineBrain Camera rotations LOCKED

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:
Video1

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);
        }
    }

}

Can you show your CinemachineVirtualCamera inspector please? With all the sections open.

Hello, Thanks for your quick response. Here it is:

And this is the PlayerVirtualCamera:

Is this some kind of 1stPerson game?

If so, why not put the vcam as a child of the player, and just rotate the player? No need to ever touch the vcam directly.

Also, you shouldn’t tag the vacm as the MainCamera, because it isn’t.

PlayerVirtualCamera is a child of the player. I changed MainCamera to Untagged but nothing changed. And yes this is 1stPerson game

This is the another GIF:

Video2

Actually i tried to just rotate my player but nothing happened with this code;

public GameObject player;

void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == player)
        {
            player.transform.position = newWorldPosition;
            player.transform.Rotate(0, -90, 0);
        }

Since you have the vcam’s position and rotation controls set to Do Nothing, the vcam is passive, and takes its position and rotation from its transform.

I suspect that you have some script somewhere that’s messing with the transforms of the vcam or one of its parents.

Try this experiment: Eliminate CInemachine by disabling your MainCamera (with the brain), and replace the CinemachineVirtualCamera component with a Camera component. Does the problem still happen?

It might help with the debugging to add some geometry to the player object, so you can see its orientation in the scene view.

Like this? When i eliminate the CinemachineBrain, player is moving but camera stays fixed. When i disable camera, i see a black screen

No.

  1. Delete the Main Camera object.
  2. Find the CinemachineVirtualCamera component (the one inside your player). Delete it and replace it with a Camera component.

This will just embed the camera inside your player, old-school style. No Cinemachine.

Well my rotation changed but not my HEROPLAYER. My camera rotation turned -90. Btw, when the game starts, i cant rotate my player manually

Unity

I think this problem about my ready-made FPSController asset. I’m using UHFPS KIT

I’m not familiar with that asset, so can’t provide help with it. Please let us know when you find the solution.

1 Like