Forum rules - please read before posting.

Change background (different size) and Camera/Switch

Hi everybody,
AC 1.74.5 and Unity LTS 2020.3.25f1.

I have this situation (https://drive.google.com/file/d/1xszyRZP6EGxA8apNNEfWHz6gPKVUOZxP/view?usp=sharing): a first background 1920x1080 and a second one 7200x2160. When I click on a hotspot (near the right corner of the room01) I have to change the background from the first one to the second one. Using the visibility it's very easy, but I have a little issue with the camera. The second one has a vertical and a horizontal scroll, while the first one is "fixed". When I change the background I change also the camera (Camera/Switch). If I change camera with "Target is Player" checked (in the second camera) I see the camera scrolls horizontally and the player goes to the center (not correct in this case) . If "Target is Player" is unchecked the change background is correct (the player remains in the same position), but then I can't scroll on the new background. Is there a way to make this type of camera transition (keeping unchanged the position of the player (camera scroll) but with the player can move using scroll in the second camera) ?

Thank you very much.

Comments

  • As this a visual/animation problem that's difficult to convey through words, a video or gif would be helpful to explain things if you can share one.

    I'm assuming the camera in question is a GameCamer2D?

    For the camera to scroll automatically, however, a Target for it is necessary. If the Player is appearing in the centre, you can try raising the Track freedom value in the camera's Inspector so that off-centre positions are allowed.

    The camera's Target doesn't necessarily have to be the Player, however. If you uncheck Target is Player?, you can assign a different Transform. This could be a child object of the Player that's offset in such a way that causes the camera to appear correct when transitioned to, but still scrolls when the player moves.

  • Hello Chris, thank you. Here two short clips to illustrate the issue:

    I tried with "Track freedom" but then the player is too far left or right. I tried with a object in scene but, obviously, I haven't scroll. I haven't understand how to put a target, child of my player: my player is a prefab and I can't to put a child of it in the Target field.

    Thank you very much.

  • I confirm it's a GameCamera2d.

  • my player is a prefab and I can't to put a child of it in the Target field.

    You can place it in the scene, and use a custom script to attach it to the Player as they spawn in.

    A custom script will be necessary, in any case, to position the target in the centre of the screen as the camera switches:

    using UnityEngine;
    using AC;
    
    public class CentreCameraTarget : MonoBehaviour
    {
    
        public _Camera bigCamera;
    
        private void OnEnable ()
        {
            bigCamera.targetIsPlayer = false;
            bigCamera.target = transform;
    
            EventManager.OnSetPlayer += OnSetPlayer;
            EventManager.OnSwitchCamera += OnSwitchCamera;
        }
    
        private void OnDisable ()
        {
            EventManager.OnSwitchCamera -= OnSwitchCamera;
            EventManager.OnSetPlayer -= OnSetPlayer;
        }
    
        private void OnSetPlayer (Player player)
        {
            transform.SetParent (player.spriteChild.transform);
        }
    
        private void OnSwitchCamera (_Camera fromCamera, _Camera toCamera, float transitionTime)
        {
            if (toCamera == bigCamera)
            {
                transform.position = fromCamera.Camera.ViewportToWorldPoint (new Vector3 (0.5f, 0.5f, 1f));
            }
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.