Forum rules - please read before posting.

Object inspection and rotation.

I've been following the physics demo video to pick up and rotate 3D objects. But I'm trying to have the object float in the middle of the screen while the rest of the game is paused. I think the closest example I can give is the recent Resident Evil games (7, 2 remake) or the original within the inventory menu. The player should be able to rotate the object with either the mouse or the directional keys. Is it possible to do this through AC?

Comments

  • Not natively, but a custom script could handle object rotation while you temporarily disable AC using the Engine: Manage systems Action.

    Each item has a "Linked prefab" property, that you can use to assign a "3D rotateable item model, with scripts" prefab to each item. To access this prefab when an item is clicked on in a regular InventoryBox menu element, you can hook into the OnInventoryInteract custom event:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class InventorySpawnExample : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnInventoryInteract += OnInventoryInteract;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventoryInteract -= OnInventoryInteract;
        }
    
        private void OnInventoryInteract (InvItem _item, int iconID)
        {
            GameObject obToSpawn = _item.linkedPrefab;
            GameObject spawnedObject = GameObject.Instantiate (obToSpawn); // Spawn the object
            // Position in front of the camera, etc
        }
    
    }
    
  • Thanks Chris!
    I want the player to be able to examine the item before adding it to their inventory as well as within it. Will this work fine for that, or would that require something different?

  • The above code would be used to spawn something when an item is clicked in the inventory, but the same code could be shared either in a custom action or in the OnInventoryAdd event. I would recommend sticking to just one situation (e.g. clicking the inventory item in the menu) and branching out to others once you've got what you want.

  • Hi Chris. Testing this out today with the generic UI menu. Does this component go in the evidence object itself or is it a controller object that just needs to be in the scene?

  • It just needs to be in the scene, though it's more of an example than anything. The code that actually handles the inspection/rotation is separate, and would need to be on the "evidence object".

  • Hi Chris. The code seems to spawn a clone of the linked prefab, but the prefabs mesh render does not show. Does the linked prefab need to be the pickup parent for that object or the base object itself? I assumed the pickup as it contains the moveable component.

    Also, using the generic menu would be fine, but how would I use a full-screen menu like in resident evil that would cover the game world but not the examine object prefab?

  • Where in relation to the camera is it spawning? You can dynamically position it in front of the camera with e.g.:

    float distanceFromCamera = 1f;
    spawnedObject.transform.position = Camera.main.transform.position + (Camera.main.transform.forward * distanceFromCamera);
    

    You'd want the linked prefab to be the root of whatever object you want to spawn, but I've been assuming you'd use a separate system to AC's "PickUp" system, as a custom-built one may be more practical for your specific needs. If you want to use a PickUp, however, I'd recommend making a test scene with just that in there to be sure it works as you intend first.

    To have an "overlay" menu appear, you'd probably want to also spawn (or turn on) a Canvas that's placed on a separate layer that can only be viewed by a second, separate camera. This second camera would then have it's Depth changed so that it renders things above the MainCamera. If you placed this second camera so that it was facing the scene's origin, you could probably do without the positioning code above, since it would be best-spawned at the origin anyway.

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.