UHFPS
  • 👋Welcome
  • 🎲Installation
    • URP - Project Setup
    • HDRP - Project Setup
    • Packages Setup
  • 🎮Getting Started
    • References
  • ⬆️Update Process
  • 📑Changelog
  • 📍Roadmap
  • ❔Support
  • 📚Guides
    • Managing Inputs
      • Adding Inputs to UI
      • Setting up Input System
    • State Machines
      • Adding Player States
      • Adding AI States
    • Save/Load Manager
      • Previous Scene Persistency
      • Encryption
    • Customizing UI
    • Interactions
    • Inventory
    • Player Items
    • Dynamic Objects
    • Motion Controller
      • External Motions
    • Hiding System
    • Narration System
    • Jumpscares
    • Puzzles
    • Objectives
    • Cutscenes
    • Options Manager
    • Game Manager
    • Localization
    • URP Specific
  • ⚙️Integrations
    • Emerald AI 3.0
    • AI Tree
    • Meet and Talk
Powered by GitBook
On this page
  • Adding New Dynamic Objects
  • Dynamic Door
  • Dynamic Drawer
  • Setting Unlock Dynamic Script
  1. Guides

Dynamic Objects

PreviousPlayer ItemsNextMotion Controller

Last updated 2 months ago

Adding New Dynamic Objects

  1. To make an object dynamic (such as a door, drawer, lever, or valve), add a Dynamic Object component to the object.

  1. Select the object dynamic type by clicking on the icons located at the top of the component.

  2. Choose the Interact Type for the dynamic object, which can be either Dynamic, Mouse, or Animation type. Once you've selected the Interact Type, the References section will change, requiring you to assign all the necessary references to ensure the dynamic object works properly.

The Target field refers to the object where all interactions will be applied. This can either be the current object where the Dynamic Object component is added or a parent object.

Dynamic Door

Make sure that the Pivot Mode is set to Pivot and Pivot Rotation to Local. If this will be set incorrectly, a prompt will appear.

  1. To configure a dynamic door, begin by setting the Open Limits, Hinge, and Forward Axis.

By using curves, you can specify the speed change when opening or closing the dynamic object. The curve should be defined between 0 to 1 values.

  1. Open Limits is actually an angle how the door should open. Rotate the door to its open position, note the hinge value, and update the Open Limits -> Max limit accordingly.

  1. Rotate the door back to the closed position. Adjust the Target Hinge (the axis where the door pivots) and Target Forward (the axis along which the door mesh extends).

Make sure you have gizmos enabled, it will help you set up the dynamic object correctly.

In certain situations, if a door or custom openable model has a different pivot rotation, you can use axis mirroring to maintain positive axes. For instance, if an axis is set to X, toggling the mirror option will switch it to X_Negative, and vice versa.

The same principle applies to the Starting Angle, if the open position is reversed (e.g., -90 is open and 0 is closed), enabling mirroring will invert that angle as well.

Dynamic Drawer

If you select the Drawer dynamic type, you can determine the min/max open limits by copying the position from the corresponding axis, as demonstrated in the image below.

The process of configuring a switchable or rotatable dynamic type is similar to the previous steps.

Setting Unlock Dynamic Script

To use a custom unlock dynamic script, create a script that implements the IDynamicUnlock interface. By doing so, you will be prompted to implement the OnTryUnlock() method, which will be called when you interact with the locked dynamic object. Here is a code snippet for a simple dynamic unlock script:

using UnityEngine;
using UHFPS.Runtime;

public class TestUnlock : MonoBehaviour, IDynamicUnlock, IInventorySelector
{
    public ItemGuid UnlockItem;
    private DynamicObject dynamicObject;

    public void OnTryUnlock(DynamicObject dynamicObject)
    {
        Inventory.Instance.OpenItemSelector(this);
        this.dynamicObject = dynamicObject;
    }

    public void OnInventoryItemSelect(Inventory inventory, InventoryItem selectedItem)
    {
        if (selectedItem.ItemGuid != UnlockItem)
            return;

        // unlock dynamic object
        dynamicObject.TryUnlockResult(true);
    }
}

If you interact with the locked dynamic object using this code, you will be prompted to use an item from your inventory. When you choose the item, OnInventoryItemSelect() will be triggered, which will unlock the dynamic object if the item is correct.

To use the dynamic unlock script, simply assign the reference to the script that implements IDynamicUnlock interface in the Unlock Script field.

A good example of using a custom unlock script is the lockpicking puzzle.

📚