Forum rules - please read before posting.

Instantiating 3D model at cursor

I am trying to instantiate an inventory item as a 3D model at the cursor point so that it is possible to rotate, drop or throw a 3D model setup with physics. When I click on the inventory item in the inventory box and drag the item into the main screen area I would like it to appear as the 3D model of the item so that I can manipulate the model in the scene and drop, rotate or throw it at that point. I am using FP perspective.

Is it possible to do this using the current actions available or will I need to script this sequence? Any help would be greatly appreciated.

Comments

  • It would need to be scripted.  The first step would be to assign the 3D model / prefab as the item's "Linked prefab" field in the Inventory Manager, which can be used to aid scripting systems such as these.

    You can get an API reference to that field, like any Manager field, by right-clicking the field's label.

    You could experiment with making the item a PickUp object, which already has rotate/throw etc functionality (see the rock in the Physics demo)

    Placing an item at the cursor in world space is fairly trivial, and you should be able to dig something up easily from the Unity forum.  The provided "World Space Cursor Example" script, however, also demonstrates how this can be done.

    If you want the object to occur when dropping the inventory in the scene, you would probably need to do it via a regular Hotspot "Use inventory" interaction, which is e.g. placed in front of the camera so that it can be reached at all times.  (The Hotspot can be disabled/enabled dynamically only when an item is selected, but that step can come later).

    You can define a global "Use on Hotspot" unhandled interaction ActionList at the top of the Inventory Manager, which will run whenever using an item on a Hotspot has no pre-defined Interaction.  This ActionList would then run the code needed to spawn the item's linked prefab.

    To avoid the need for a custom Action, you can write the necessary code in a standard C# script and use the Object: Send message / Object: Call event Actions to invoke it.

    The currently-selected item at any time can be read with:

    AC.KickStarter.runtimeInventory.SelectedItem;


    Unfortunately, this will be set to null when used with the Hotspot, so you'll need to write its value to an internal variable in your script's update function, e.g.:

    AC.InvItem lastSelectedItem;
    void Update()
    {
      if (AC.KickStarter.runtimeInventory.SelectedItem != null)
      {
        lastSelectedItem = AC.KickStarter.runtimeInventory.SelectedItem;
      }
    }


    You can then retrieve that item's linked prefab with:

    lastSelectedItem.linkedPrefab;

  • Hi Chris
    Sorry about the delayed reply. Thanks for the tips, I'll give that a go. I appreciate your assistance.
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.