Forum rules - please read before posting.

Close Up Item Examining and Interaction

Hi guys

I'm trying to implement a system to allow the player to inspect and interact with an object in 3D from a zoomed in perspective.

I have seen a few threads on here about this and also a section within the tutorials although each seems to be a different way to implement it and what I'm hoping to do is a little different so I'm wondering what the best way to go about this is.

I'm unsure if what I'm asking is possible within the system but figured I'd at least bring up the discussion

for clarity I'll refer to this view mode as "Object Inspection View"

THE SYSTEM
Upon interaction with an object the background is pointed where the player was last looking, blur effect applied
Gameplay is disabled
The object is centered in view
The player is able to rotate the object with keys (A,D as example)
The player can zoom in a set amount on keypress (Z as example)
The cursor is still enabled allowing the object to have interactions on it eg right click for examine dialogue

I've seen mention of using a separate camera that the view would be jumped to to look at these but as I'd prefer to have the background be the last view the player had would this mean attaching this to the player view camera?

A good example of what I'm referring to can be seen here within Resident Evil

THE IMPLEMENTATION
There are a few ways I'm hoping to implement this system

The first is within the world/scene/playspace. Eg the player sees a medicine cabinet, opens it to find a bottle of pills. Upon clicking on the hotspot for the pills "Object Inspection View" is activated.

The second is from the inventory. When the player hovers over an item in the inventory I want to provide a "use" interaction, a "combine" and an "examine" when the player selects the examine I'd like that to take them to "Object Inspection View"

The third feature if possible is to add interactions to this view. An example being with the bottle of pills if the cap was clicked an animation might play of it unscrewing or with an old radio clicking the back bottom cover for an animation to show there's no batteries in it. Normally I'd view doing this with hotspots but if the objects can be rotated I'm unsure on how to apply this.

I'm not sure how much of this can/should be done with AC, for this system would it be better to implement some kind of unity UI as opposed to the AC inventory system?

Any help is Greatly appreciated

Comments

  • edited September 2021

    It'd be a mix of custom scripting and AC, starting simple and adding more complexity (e.g. zooming, blurred background) as you go.

    Each approach will differ based on the project's needs, but the "Chamber demo" example package on the Downloads page does something similar - you may want to pick it apart to see how it works.

    As the objects are to be in 3D, but interactive, stick to Hotspots but set their "Interactions source" to "Asset File". Your objects will need to be prefabs, so that they can be added to the scene when examined - meaning the Interaction ActionLists will need to be asset files.

    A Hotspot won't control its object's position - so you can attach a simple script to it to rotate upon input from the player, without the two interfering. Something like:

    using UnityEngine;
    
    public class RotateInput : MonoBehaviour
    {
    
        [SerializeField] private float moveSpeed = 5f;
    
        private void Update ()
        {
            float horizontalInput = Input.GetAxis ("Horizontal");
            transform.Rotate (Vector3.up, horizontalInput * Time.deltaTime * moveSpeed);
        }
    
    }
    

    It'll probably be easier to rely on inventory items for all close-ups - even those that are only in the scene. You can create dummy items for scene objects that aren't added to the Player's inventory, but just used as reference.

    Essentially, beginning a close-up will be a case of:

    • Preventing player movement
    • Spawning the close-up prefab into the scene at some place away from the rest of the scene
    • Switch to a "close up camera" that's positioned in front of this spawned prefab

    These steps can be performed with Actions, so create an ActionList with a Player: Constrain to lock movement, an Object: Add or remove Action to add a prefab (leave this blank for now), and a Camera: Switch Action to switch to this close-up camera. Make this camera a prefab and check Retain in prefab? on its Constant ID component so that it'll be consistent for each scene you place it in.

    Since these three steps will be the same for each item (except which prefab is actually spawned), you'll want to make use of ActionList parameters.

    For each close up, create an Inventory item for it and assign the "close up prefab" as the item's "Linked prefab" property. Then, in your "Begin Close-up" ActionList, create an Inventory Item parameter, and use it to override your Object: Add or remove Action's Object to add field.

    If you're unfamiliar with ActionList parameters, a tutorial can be found here.

    You should now be at a point where you can begin "Object Inspection View" by using the ActionList: Run Action to call this "Begin Close-up" ActionList, setting the value of its Inventory item parameter to match the item you want to view.

    I can advise further on e.g. ending this view etc, but see how you go with this first - it's a complex topic.

  • Thanks Chris

    I'm trying to implement this as you've advised.

    Unity is throwing this error on the RotateInput Script, apologies for typing it out but the image link button isn't liking adding an image today

    on this line
    Vector2 horizontalInput = Input.GetAxis ("Horizontal");

    it throws this error

    error CS0029: Cannot implicitly convert type 'float' to 'UnityEngine.Vector2'

    and on this line

    transform.Rotate (Vector3.up, horizontalInput * Time.deltaTime * moveSpeed);

    this one

    error CS1503: Argument 2:
    cannot convert from 'UnityEngine.Vector2' to 'UnityEngine.Space'

  • My mistake - replace "Vector2" with "float".

    I've corrected the script above.

  • Thanks Chris

    That's fixed the error.

    I've followed these steps through but must be doing something wrong.

    I've tried to use the embed image button for screenshots I've taken and uploaded through imgur but they aren't working for some reason, I've instead pasted the links hopefully they work ok.

    I'll use the example of a pill bottle here

    I've created a second camera from an AC simple camera
    I've labeled this "Object Examine-Cam"
    Object Examine-Cam is a prefab with a Constant ID set to Retain in prefab

    I have the object, a pill bottle as a prefab in a project-prefabs folder
    I have created an inventory object for this and correctly set its Linked Prefab to that of the pill bottle prefab
    https://imgur.com/a/bjye1UX

    I've created the RotateInput script and attached it to the prefab for the pill bottle
    https://imgur.com/Y4nwGgV

    I've created an ActionList that exists outside of the scene called BeginCloseUp
    This ActionList has a parameter called "InventoryItem" of type inventory item

    The first action is a player-constrain
    Then an Object- Add Remove, the object to instantiate is based on the parameter
    Then a Camera Switch to the "Object Examine-Cam" mentioned above
    https://imgur.com/qHbBsxI

    For testing I've set the BeginCloseUp ActionList to be sparked both from the "examine" hotspot in the scene and from clicking on the item in inventory.

    I can get the camera to switch but no item is being shown in that view and as such there's nothing to rotate

    My first thought was that there was nothing up until now being sent to the InventoryItem parameter inside BeginCloseUp Action List so I tried the following

    There is a hotspot in the scene for the pillbottle. On clicking this hotspot it has an ActionList-Set Parameter action. Its source is AssetFile-BeginCloseUp-InventoryItem-NewValueEnteredHere-Pill Bottle (the inventory item with the linked prefab)

    https://imgur.com/BVXTk5n

    That didn't do anything. Next within BeginCloseUp ActionList I tried setting the Object Add/Remove position to be "Relative to Active Camera" I then tried this setting with the "Camera Switch" action happening both before the Object Add/Remove and after it. This isn't doing it either. I then tried creating a marker at what would be the center of that cameras view and setting the Position to be Relative to the marker but that didn't do anything.

    As a side question that's a little irrelevant until an item is actually appearing but regarding the rotation of an object and the RotateInput script do I need to set some new input keys for the rotation?

    Cheers

  • Things look OK in the screenshots.

    The "Relative to" options in the Object: Add or remove Action mean that the spawned object's position is a calculated by adding the position of the relative object to the position of the prefab. Make sure that the prefab's position is just off-centre e.g. (-1,0,0) if the camera is facing along the X axis.

    The main thing to check, though, is to see if the object is actually appearing in the Hierarchy. Make sure that the prefab isn't present in the scene before running, and then search for it once the ActionList has been run. Go through the Console window, too, to see if it's reporting anything amiss.

    regarding the rotation of an object and the RotateInput script do I need to set some new input keys for the rotation?

    The script relies on an input named "Horizontal", which is part of Unity's default inputs. You can rename / remap it to something else if desired, though.

  • Running it through again nothing is coming through in the Console Window

    The object/prefab is indeed spawning in the hierarchy/scene but I'm having some trouble getting it to spawn in front of the camera as it seems to want to keep spawning it behind it.

    I can't quite seem to get the object rotation working either.
    with the game running I can pull the object into the view of the "inspection camera" but neither keyboard nor mouse movement have the prefab moving in any way.

    I have the RotateInput script attached to the prefab, is there something else I'm missing like attaching a drag script to the prefab or something?

  • I'm having some trouble getting it to spawn in front of the camera as it seems to want to keep spawning it behind it.

    What is the orientation of your camera vs the position of the original prefab?

    The alternative would be to have it appear "Relative To Marker", and clear the original prefab's position, so that there's no offset.

    I can't quite seem to get the object rotation working either.

    The default "Move Speed" value is quite low. Try raising it to 100 in the Inspector.

  • Aha

    you were absolutely right, it was rotating just at a speed so low it wasn't noticeable. After bumping that up the rotation is working like a charm.

    I've attached an imgur link, hopefully it should show the multiple uploaded images.
    https://imgur.com/a/sLC6K3i

    The First is the object/prefab we're inspecting in relation to the camera (I've switched with a big orange cube prefab for testing purposes)

    The Second is The ActionList that I've tried to set up with a marker

    The Third shows the marker which is about center within the Cameras view but as in the first screenshot the Prefab is being spawned on to opposite side of the camera to this marker.

    The Fourth shows the direction/angle the camera is facing.

    In regards to the cameras position this is just where the camera originally spawned and while getting this up and running I've just left it where it is and decided to work around it.

    What I'd like to try and aim for is to have two different examine views. One for inventory objects and one for "items within the scene" I'm thinking this could be done with two cameras and either creating two different ActionLists that are object dependent or having a parameter that needs to be met and depending on that it decides which camera to send it to.

    The examine view for inventory items would just have a plain black background behind the object but for the "objects in scene" I'd be cool to have the background behind the object be that of the last view the player had as in the resident evil screenshot above.

    In terms of having the players last view I'm thinking this might be able to be done either by sending the player cameras last transforms information to that of an examine camera. As that could be at any angle I'm unsure of what would be the best way to always tie the object being examined to the center of that view? would it be using a marker?

    I figure it may as well be worth asking this stuff now in case it changes how to place the object in view etc

  • Is your first screenshot as things appear once the ActionList has been run?

    What is your prefab's original position, and where is the spawned object relative to the Marker it should be placed at?

    For cameras, you can probably make do with an overlay camera, by activating the previous camera's Camera component and giving it a lower depth. It's something you can try with the Inspector fields while in close-up mode, but let's get the object spawning in the right place first.

  • Sorry yes the first one is during gameplay after the ActionList has been run

    Right now that prefab doesn't exist in the scene anywhere and is only spawned during runtime after the ActionList has been called.

    https://imgur.com/a/nNG6Zw3

    The first screenshot is during runtime in which the orange cube is the spawned object and the gizmo is where the marker is placed that its position is set to be relative to.

    (apologies for the purple tint on runtime hope it's still readable)
    The second Screenshot is the cubes transforms upon being spawned (where it's spawning to)

    The third is the markers transforms

  • What are the position values of the original prefab?

  • That was it!! Seems obvious now.

    I've reset the transforms on the prefab and now it's appearing perfectly where it should be.

    Would you mind explaining the overlay camera idea above a little more? would this be an extension of the current camera in use or would this be a newly created camera?

  • As this is related to rendering, AC isn't involved so much here. But basically you want to have both your AC MainCamera and previous-gameplay camera rendering at the same time, using the Camera's Depth and Culling Masks properties to properly overlay one over the other.

    Try this with a pair of cameras in a fresh scene without AC to see what needs to be set. The exact process may vary based on your render pipeline. On the AC side of things, it'd be a case of enabling your previous-gameplay camera's Camera component at the time you switch to your "close up" camera - and disabling it afterwards.

    This would be a case of hooking up to the OnSwitchCamera custom event in a custom script, and checking if you're switching to/from your close-up camera. Something like this should do it:

    using UnityEngine;
    using AC;
    
    public class CloseUpCameraOverlay : MonoBehaviour
    {
    
        public Camera closeUpCamera;    
    
        private void OnEnable () { EventManager.OnSwitchCamera += SwitchCamera; }
        private void OnDisable () { EventManager.OnSwitchCamera -= SwitchCamera; }
    
        private void SwitchCamera (_Camera old, _Camera newCamera, float tt)
        {
            if (newCamera == closeUpCamera && old != newCamera)
            {
                old.Camera.enabled = true;
            }
            else if (old == closeUpCamera && old != newCamera)
            {
                newCamera.enabled = false;
            }
        }
    
    }
    
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.