Forum rules - please read before posting.

Is it possible to have an action played based on angle of a rotated object?

edited January 2 in Technical Q&A

Hey! I'm using draggables and the return pickups script from the AC wiki so I can inspect items, rotate them and discover stickers with numbers on them as a part of a larger puzzle. It works amazingly well but I would love to be able for the character to play dialogue once the sticker is visible, basically saying something like "Okay this one has number 5" when the sticker is visible... Is it possible to place some marker/hotspot that's either visibility-related or rotation-related that will trigger when in view without clicking? Because I'm holding the left click for the entire duration of the rotation... Thank you for any ideas!

Comments

  • Okay so I ended up creating a trigger that's a child of the object and is sticking out in one direction so when you rotate it, it touches the player and triggers. Would still appreciate a more elegant solution if it exists though!

  • That's a smart solution! It's possible to use a script-based approach instead, but your way makes it visually clear from a design / debug view.

    For the script approach, you could try attaching a Hotspot with a Use interaction, and then running that automatically when the dot product of its relative position compared with that of the camera reaches some threshold value. Something like:

    using UnityEngine;
    using AC;
    
    public class AutoUseHotspot : MonoBehaviour
    {
    
        public Moveable_PickUp pickUp;
        public Hotspot hotspot;
        [Range (0f, 1f)] public float threshold = 0.8f;
    
        void Update ()
        {
            if (!KickStarter.stateHandler.IsInGameplay ()) return;
    
            Vector3 relativePosition = transform.position - pickUp.transform.position;
            Vector3 cameraRelativePosition = Camera.main.transform.position - pickUp.transform.position;
            float dotProduct = Vector3.Dot (relativePosition, cameraRelativePosition);
    
            if (dotProduct > threshold)
            {
                hotspot.RunUseInteraction ();
            }
        }
    
    }
    
  • Thank you so much, Chris! I'll test it out when I get home.

  • Hmm, it doesn't seem to work. I can't select anything for the Moveable_PickUp for some reason.

    NullReferenceException: Object reference not set to an instance of an object
    AutoUseHotspot.Update () (at Assets/XXX/AutoUseHotspot.cs:15)

    Tried to change it to GameObject in the code so I can select the object but that's probably not enough.

  • Have you assigned all the fields in its Inspector?

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.