Forum rules - please read before posting.

Camera zoom in dialog

Chris, please tell me how to automatically implement the camera zoom in when the dialogue starts and move away when the dialogue is over?

«1

Comments

  • It depends on how you want to classify when dialogue as being run. You could automate this whenever a line of speech plays, but with pauses, animation etc that can go in between it's probably best to zoom in for the duration of the entire ActionList.

    If you assign your dialogue-sequence ActionLists a special tag (e.g. "Dialogue"), then you can have a custom script control the camera zoom when such lists being and end.

    An object's Tag can be set to the left of its Layer - see Unity's docs on this here:
    https://docs.unity3d.com/Manual/Tags.html

    Attach this script (AutoZoomCamera.cs) to the active GameCamera (not the MainCamera) and check its Inspector values. It assumes the Camera uses Orthographic Projection - otherwise it'll need to be tweaked to affect the Field Of View.

    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class AutoZoomCamera : MonoBehaviour
    {
    
        public float zoomFOV = 3f;
        public float zoomSpeed = 3f;
        private float normalFOV;
        public string actionListTag = "Dialogue";
        private Camera _camera;
        private HashSet<ActionList> actionLists = new HashSet<ActionList> ();
    
        private void Start ()
        {
            _camera = GetComponent<Camera> ();
            normalFOV = _camera.orthographicSize;
            actionLists.Clear ();
        }
    
        private void OnEnable ()
        {
            EventManager.OnBeginActionList += OnBeginActionList;
            EventManager.OnEndActionList += OnEndActionList;
        }
    
        private void OnDisable ()
        {
            EventManager.OnBeginActionList -= OnBeginActionList;
            EventManager.OnEndActionList -= OnEndActionList;
        }
    
        private void Update ()
        {
            float targetZoom = actionLists.Count > 0 ? zoomFOV : normalFOV;
            _camera.orthographicSize = Mathf.Lerp (_camera.orthographicSize, targetZoom, Time.deltaTime * zoomSpeed);
        }
    
        private void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
        {
            if (actionList.gameObject.CompareTag (actionListTag))
            {
                actionLists.Add (actionList);
            }
        }
    
        private void OnEndActionList (ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
        {
            if (actionLists.Contains (actionList))
            {
                actionLists.Remove (actionList);
            }
        }
    
    }
    
  • If you assign your dialogue-sequence ActionLists a special tag (e.g. "Dialogue"), then you can have a custom script control the camera zoom when such lists being and end.

    Sorry, it's a little unclear:
    1. What do you need to attach the tag to?
    2. Which ActionLists command attaches a tag?

  • Set the tag to the GameObject of any ActionList that you want the camera to be zoomed in while playing.

  • https://streamable.com/2mo9jx
    If I change the layer by adding a tag but the game does not see the character, tell me how to fix it correctly?

  • Set the Tag - not the Layer. These are two separate properties.

    Tags are set to the left of the Layer field - again, see Unity's docs here:
    https://docs.unity3d.com/Manual/Tags.html

  • Sorry, I mixed up layers and tags, I'm still learning to be a unity master :D
    I installed the tag, but did not see the result, what else can I check?

  • Tag the ActionList that you wish to zoom in while running - not the character.


  • How do I tag "ActionList" if it's inside a character? Or I didn't get you, sorry.

  • Tag the GameObject of the Interaction - nothing to do with the NPC's GameObject or Inspector.

  • Please show a screenshot of what I should do, otherwise I'm completely confused. Excuse me.

  • edited January 14

    Here you go bro :wink:
    https://streamable.com/7dxdrd

    I changed it a bit and it works nice for First Person too, thanks chris.

    If anyone sees this later and wants it for a First Person Camera, just change any of the _camera.orthographicSize; to _camera.fieldOfView

  • https://streamable.com/f88ayr
    The script most likely works on the camera does not affect anything, what am I doing wrong?

    snan p.s.: thx!

  • edited January 15

    You are putting the Dialogue Tag ** on the **WRONG OBJECT **, you have to **TAG THE OBJECT WITH ACTIONLIST ON IT, it has a symbol on it's Gameobject in the Hierarchy!
    Carefully watch my video, which object i'm clicking on. I even let it highlight.

    Dialogue Tag ON the Actionlist Object

    NOT the Hotspot Object!!!!!!!

    Click on this field, and that SHOWS you the object where you have to put the tag

    CLICK HERE ON THE NAME IN THAT FIELD, THEN IT SHOWS YOU

    Like here, it has those two symbols on the side in your hierarchy, you're clicking the hotspot without the actionlist:
    OR HERE IN YOUR HIERARCHY WITH THE ACTIONLIST SYMBOL That is the Object where you put the Dialogue Tag!

  • snan, thanks a lot!
    https://streamable.com/a8r4rt
    Everything works fine, but when the effect of selecting the "dialog box" appears, the zoom effect is disabled, please tell me, do I need to change the script itself or assign a tag somewhere else?

  • Please tell me Chris, is it possible to tweak the script a bit so that it keeps track of whether there is a branched choice in the dialog that did not turn off the approximation?
    https://streamable.com/a8r4rt

  • edited January 17

    Found two problems, one of them with a selection list, (zoom moves away although there is a tag)
    And the second one, with the exit from the naninovel asset, although goes into a dialogue with the tag
    https://streamable.com/a48kbx

    Tell me what can be done here?

  • The script only reads the tag for ActionLists - not Conversations.

    To have the camera be zoomed in while Dialogue Options are displayed, the script must be amended:

    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class AutoZoomCamera : MonoBehaviour
    {
    
        public float zoomFOV = 3f;
        public float zoomSpeed = 3f;
        private float normalFOV;
        public string actionListTag = "Dialogue";
        private Camera _camera;
        private HashSet<ActionList> actionLists = new HashSet<ActionList> ();
    
        private void Start ()
        {
            _camera = GetComponent<Camera> ();
            normalFOV = _camera.orthographicSize;
            actionLists.Clear ();
        }
    
        private void OnEnable ()
        {
            EventManager.OnBeginActionList += OnBeginActionList;
            EventManager.OnEndActionList += OnEndActionList;
        }
    
        private void OnDisable ()
        {
            EventManager.OnBeginActionList -= OnBeginActionList;
            EventManager.OnEndActionList -= OnEndActionList;
        }
    
        private void Update ()
        {
            float targetZoom = DoZoom () ? zoomFOV : normalFOV;
            _camera.orthographicSize = Mathf.Lerp (_camera.orthographicSize, targetZoom, Time.deltaTime * zoomSpeed);
        }
    
        private void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
        {
            if (actionList.gameObject.CompareTag (actionListTag))
            {
                actionLists.Add (actionList);
            }
        }
    
        private void OnEndActionList (ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
        {
            if (actionLists.Contains (actionList))
            {
                actionLists.Remove (actionList);
            }
        }
    
        private bool DoZoom ()
        {
            return actionLists.Count > 0 || KickStarter.playerInput.activeConversation;
        }
    
    }
    
  • The script works fine, but when you exit the NaniNovel asset back to the AC, the script does not turn off, maybe you can set some parameter to disable the script and return the camera?
    https://streamable.com/kag2oh

  • The Object: Call event Action can be used to disable the script at runtime, disabling its influence.


  • And what exactly should be specified in the shutdown?
    the path to the script or some kind of event?

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.