Change the camera, the confiner or what?

Hi!

I’m working in a dungeon with multiples rooms in the same scene. My problem is when to player touch the edge of the room and teleport to the next one and my Cinemachine Confiner was setup to the previous room.

What is better, create a confiner to each room and change the reference in the Cinemachine Confiner component ( change the Bounding Shape 2D, but i don’t even know if this work,) or create a camera with own confiner to each room? Or another suggestion too, because this mine sounds both awful.

Thank you!

Each room can come with its own vcam, with a confiner set up for it. When the player enters the room, activate the new vcam and deactivate the old one. For this you can use CinemachineTriggerAction script. There is no significant performance cost to using this approach.

Thank you! I already was found a solution, i don’t know if the best one, but works this:

When the player touch the edge of the map (a gameObject with a trigger collider, transformed in to a prefab to reuse in any transition), with this:

private void OnTriggerEnter2D(Collider2D other)
{
    roomTransferScript.StartTransition(nextConfiner, nextSpawn);
}

This roomTransferScript reference the RoomTransfer script in the canvas (with the black image to fade in and fade out transition) that have this functions:

public void StartTransition(PolygonCollider2D nextConfiner, Transform nextSpawn)
{
    newConfiner = nextConfiner;
    newSpawn = nextSpawn;
    animator.SetTrigger("Start");
}

void PlayerTransfer()
{
    // update confiner
    confiner.m_BoundingShape2D = newConfiner;
    confiner.InvalidatePathCache();

    // teleport player
    player.transform.position = newSpawn.position;
}

void FreezeTime()
{
    Time.timeScale = 0f;
}

void UnfreezeTime()
{
    Time.timeScale = 1f;
}

All that i do is call this functions in the screen fade animations (to be more accurated in time and don’t need to work with coroutine or things like this). Just trigger it and let the things happen, freeze time > screen fade to black > update the confiner > move the player to the new spawn > screen back to normal transparency > unfreeze time.


(have the fade_out_black that make the second part of the transition and the blank animation that let this image with transparency 0 all the time)

It’s working well, i can keep with one vcam and the confiner update happens when the screen is totally black, so don’t have visual impacts. BUT this post will be saved for possible future problems with this approuch haha.

UPDATE: if you wanna try this, make sure the animator component of the screen fade animations have the Update Mode setup with Unscaled Time, or this will be freeze together the rest of the game.