Forum rules - please read before posting.

Transform other game objects while manipulating draggable?

Is it possible to apply transformations to game objects while manipulating a draggable for things like turning cogs and stuff like that?

Comments

  • Through scripting, yes.

    You can hook into the OnGrabMoveable and OnDropMoveable custom events if you want to apply/release something specific when a particular object is held. For example, this script updates an Animator's Bool parameter whenever a pre-defined object is dragged:

    using UnityEngine;
    using AC;
    
    public class GrabEventExample : MonoBehaviour
    {
    
        public DragBase myDraggable;
        public Animator myAnimator;
        public string myBoolParameter = "IsHeld";
    
        private void OnEnable ()
        {
            EventManager.OnGrabMoveable += GrabMoveable;
            EventManager.OnDropMoveable += DropMoveable;
        }
    
        private void OnDisable ()
        {
            EventManager.OnGrabMoveable -= GrabMoveable;
            EventManager.OnDropMoveable -= DropMoveable;
        }
    
        private void GrabMoveable (DragBase dragBase)
        {
            if (dragBase == myDraggable) myAnimator.SetBool (myBoolParameter, true);
        }
    
        private void DropMoveable (DragBase dragBase)
        {
            if (dragBase == myDraggable) myAnimator.SetBool (myBoolParameter, false);
        }
    
    }
    

    If you're dealing with a Draggable moving along a Track, you can also read the object's GetPositionAlong function to sync up another object's transform or Float anim parameter with it. For example, this script updates an Animator's Float parameter with how far along a pre-defined Draggable is along a Track (ranging from 0 to 1):

    using UnityEngine;
    using AC;
    
    public class TrackPositionExample : MonoBehaviour
    {
    
        public Moveable_Drag myDraggable;
        public Animator myAnimator;
        public string myFloatParameter = "TrackPosition";
    
        private void Update ()
        {
            myAnimator.SetFloat (myFloatParameter, myDraggable.GetPositionAlong ());
        }
    
    }
    
  • edited January 2022

    So, would I make these custom actions, or how would I integrate these scripts? (Sorry about the very late response btw)

  • They are not custom Actions - they are standalone scripts you can just place in your scene. Which object(s) they are attached to does not matter, as all object references involved are defined in their Inspectors.

    They are both examples, mind. What you ultimately end up using depends on the specifics of your situation. If you can elaborate more fully I can give more specific advice.

  • I don't really have a specific use case in mind yet at least, but it's good to know that it's possible. I don't really know much C#, but I'll take a look at the scripting guide and see what I can do. Thanks for the help!

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.