Forum rules - please read before posting.

Zoom object automatically towards camera

Hi I was wondering if it's possible to have an object zoom in automatically to the camera like in this video at 5:15

Comments

  • There isn't a prefab/system for this, no - and while I'd recommend looking into a custom script / separate asset for this particular aspect, you may actually be able to get something like this up and running by using individual AC elements in combination.

    Try this:

    1. Add the object you wish to zoom as a Draggable object with its Drag mode set to Rotate Only. See the Manual's "Draggable objects" chapter for more on this topic.
    2. Freeze the Rigidbody's position in all 3 axes, and check Ignore Player's collider? in the Moveable_Drag Inspector. Tweak the other values (e.g. Angular Drag and Rotation factor to suit.
    3. Set the Remember Moveable component's Moveable state on start field to Off.
    4. Add a new Marker object as child of your Player's FPS camera. This will be where the object moves towards when zoomed in.
    5. Place a Hotspot in the scene at the same place, but make sure it's a separate GameObject and not parented to the Draggable. Give it a Use interaction.
    6. In this Interaction, create the following Actions:
    • Hotspot: Enable or disable - to disable the Hotspot
    • Player: Constrain - to disable movement in all four directions, as well as free-aiming
    • Object: Transform - to move the draggable object to the Marker (Copy Marker, Act in World-Space), and wait until finish
    • Object: Send message - to send the message "Turn On" to the draggable object
  • Thank you I will try that but player: Contrain don't work for me because I am using opsive controller.

  • player: Contrain don't work for me because I am using opsive controller.

    There'll surely be a way to disable input on the Opsive Controller, but you'll have to contact the developer for advice. If your controller script has a function in it to enable/disable input, you can call it with the Object: Send message Action.

  • I worked out how to constrain player I just had to change the integration script.
    Here is the full script:

    using UnityEngine;

    using AC;

    using Opsive.UltimateCharacterController.Input;

    using Opsive.UltimateCharacterController.Character;

    using Opsive.UltimateCharacterController.Events;

    [RequireComponent(typeof(UltimateCharacterLocomotion))]

    public class AdventureCreatorControllerHandler : MonoBehaviour

    {

    #region Variables
    
    
    
    private Vector2 defaultMouseSensitivity;
    
    private UltimateCharacterLocomotion ultimateCharacterLocomotion;
    
    private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;
    
    private Player player;
    
    
    
    #endregion
    
    
    
    
    
    #region UnityStandards
    
    
    
    private void Awake()
    
    {
    
        player = GetComponent<AC.Player>();
    
        playerInput = GetComponent<Opsive.UltimateCharacterController.Input.PlayerInput>();
    
        ultimateCharacterLocomotion = GetComponent<UltimateCharacterLocomotion>();
    
    
    
        if (playerInput != null)
    
        {
    
            defaultMouseSensitivity = playerInput.LookSensitivity;
    
        }
    
    }
    
    
    
    
    
    private void OnEnable()
    
    {
    
        EventManager.OnEnterGameState += OnEnterGameState;
    
    }
    
    
    
    
    
    private void OnDisable()
    
    {
    
        EventManager.OnEnterGameState -= OnEnterGameState;
    
    }
    
    
    
    
    
    private void Update()
    
    {
        bool canControlPlayer = (KickStarter.stateHandler.IsInGameplay() && KickStarter.playerInput.CanDirectControlPlayer());
        if (playerInput != null)
    
        {
    
            playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked())
    
                                        ? defaultMouseSensitivity
    
                                        : Vector2.zero;
    
        }
        SetControlState(canControlPlayer);
    
    }
    
    private void SetControlState(bool value)
    {
        if (value)
        {
            EventHandler.ExecuteEvent<bool>(gameObject, "OnEnableGameplayInput", true);
            player.motionControl = MotionControl.Manual;
        }
        else
        {
            EventHandler.ExecuteEvent<bool>(gameObject, "OnEnableGameplayInput", false);
            player.motionControl = MotionControl.Automatic;
        }
    }
    
    #endregion
    
    
    
    
    
    #region CustomEvents
    
    
    
    
    
    private void OnEnterGameState(GameState newGameState)
    
    {
    
        if (newGameState == GameState.Normal)
    
        {
    
            EventHandler.ExecuteEvent<bool>(gameObject, "OnEnableGameplayInput", true);
    
            player.motionControl = MotionControl.Manual;
    
        }
    
        else
    
        {
    
            EventHandler.ExecuteEvent<bool>(gameObject, "OnEnableGameplayInput", false);
    
            player.motionControl = MotionControl.Automatic;
    
        }
    
    }
    
    
    
    
    
    private void OnTeleport()
    
    {
    
        ultimateCharacterLocomotion.SetPositionAndRotation(KickStarter.player.GetTargetPosition(), KickStarter.player.GetTargetRotation(), true);
    
    }
    
    
    
    #endregion
    

    }

  • This works like a charm but is there a way to activate an input so I can do other actions like take an object and put it in inventory and also the zooming isn't working. I do have input in project settings as well.

  • I just worked out you have to hold mouse key as well as a zoom at the same time so I might try zooming with markers maybe.

  • I have worked out how to enable input.

  • It would be good if I could work out how to do mouse scrolling for zoom.

  • edited October 2019

    If you're not using AC's First Person Camera, then it'll be down to your own script to provide it. This is how AC's First Person Camera does it:

    if (canControlPlayer)
    {
        float minimumZoom = 13f; // Change to suit
        float maximumZoom = 65f; // Change to suit
    
        float scrollWheelInput = Input.GetAxis ("Mouse ScrollWheel");
        if (scrollWheelInput > 0f)
        {
            Camera.main.fieldOfView = Mathf.Max (Camera.main.fieldOfView - 3, minimumZoom);
        }
        else if (scrollWheelInput < 0f)
        {
            Camera.main.fieldOfView = Mathf.Min (Camera.main.fieldOfView + 3, maximumZoom);
        }
    }
    

    Insert that into the end of your Update function, and tweak as desired.

  • edited January 2022
    Hi there,

    i am new here and found this post because it fits to my needs so far :) So 1st: Hello everybody :)

    i made a simmilar system to this one above. i have a walk -to interaction, after that i can click on the hotspot so the 3D Model appears and i can rotate around. I also created two buttons :

    "go Back" - which brings the model back to its original position.
    "inventory"- When i click here, i want the object to appear in the inventory.

    https://ibb.co/Dg2L5xV

    I made this with an action list in the AC Menu manager, i created a new menu and the buttons for that. For the inventory i just made a "action list to run" with the "inventory Add-or remove". Works half the way i want it. In this case, i would need to create an inventory Button for each object cause i can only choose between the premade items i created in the AC Inventory manager.
    I want that the button "recognizes" the item behin the mesh and store the corresponding item in the invetory after clicking the button.

    I hope you understand my problem.
  • Ok, i was able to solve the problem with the containers. Works fine, i am ok with that.

    Though, i have a simmilar problem for the "Back" button. Still, the action list is full of specific Hotspots and GameObjects. So in this case, i need to find a way to put them into an empty GameObject or sth. like that. I can´t see a solution. Here a Screenshot of the "BackButton" Action List in order to bring the mesh back to its original position.

    https://ibb.co/tP7SK7s

  • Welcome to the community, @JackDaHack.

    If you're looking to "recycle" an ActionList, where the Actions remain the same but field values change each time it runs, you can do this with ActionList parameters.

    Parameters allow you to replace Action field values with parameter references, that are then set to the intended value at runtime. Full details can be found in the Manual's "ActionList parameters" chapter.

    In the case of your "BackButton" ActionList, you could use GameObject parameters to both set which Hotspot to enable, and which Moveable object to Transform.

    What you'd want to then do is set these parameter values at the time the close-up begins, so that they are already set up by the time BackButton is run. To do this, you can use the ActionList: Run Action's Set Parameters Only method, which allows you to set an ActionList's parameter values without running the ActionList itself.

  • edited January 2022

    Hi Chris, thx again for your quick support. That´s awesome, i had a good feeling when i 1st saw the paramaeters but i wasn´t sure how to use them . Thank you very much !

    Still i´m not sure about the back button. I replaced the orginal Action Lists on the Objects iteself and created 2 Action Lists with Parameters. One for Walking to the Object and another for "investigate Object" where the close up phase begins.

    Then i created a 3rd Action List for the "Back" button and there i also created parameters, but i don´t get the Point with the "ActionList:Run Actions Set Parameters Only. How do i link the Parameters from the "Investigate Object" to the Close Button Action List ?

  • The ActionList: Run Action can be used to assign another ActionList's parameters in bulk, without actually running the list. If you place this inside your "Investigate Object" ActionList, you can configure your "Close Button" ActionList with the correct parameter values so that when the user clicks it, it affects the correct objects.

    An alternative to this Action is the ActionList: Set parameter Action, which allows you to set an individual parameter's values, rather than all at once.

    These Actions also allow you to "pass on" a parameter value - so if your "Investigate Object" ActionList already has a GameObject parameter that represents e.g. the Moveable object you want to move towards the camera, you can transfer this value onto the "Close Button" ActionList as well.

    If things are unclear, best to share screenshots showing the issue so that I can advise more specifically.

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.