Forum rules - please read before posting.

Moveable Drag: Rotate Only Question

Hey Chris, thanks again for the awesome new update.

So playing with the new rotate only setting, a few questions about it.

  1. When it zooms to the player, can I have it return to its original position? Is this a setting I missed or wil I need a custom script/
    See this link for context
    https://drive.google.com/open?id=1-ii3QeIMjHrZz2aaQ6lcPEb6e-41Uv6B
    At the moment it zooms into the player and retains its zoomed position.

I remember there was a custom pick up script to return to position, however does not work for this.

  1. Am I able to set the Rotate only as a toggle. EG; click on object, zooms to camera, allows you to rotate till you press a button to exit?

Thanks for your help!

Comments

  • I remember there was a custom pick up script to return to position, however does not work for this.

    You're referring to this wiki script?
    https://adventure-creator.fandom.com/wiki/Return_PickUps_to_original_position

    The "Rotate Only" setting isn't new, rather the ability to use it without the need for a Rigidbody. I've updated the script to work with Drag objects as well, but likely it'll work best without a Rigidbody.

  • Awesome thank you, that works. Is there a native AC function to make it toggle-able on left click, Then click again to release? Or will this be something I ll just need to figure out with the inputs?

  • This should do it:

    using UnityEngine;
    using AC;
    
    public class ToggleDrag : MonoBehaviour
    {
    
        private string toggleDragInput = "ToggleDrag";
        public KeyCode keyCode;
        private bool waitForUp;
    
    
        private void Start ()
        {
            KickStarter.playerInput.dragOverrideInput = toggleDragInput;
    
            KickStarter.playerInput.InputGetButtonDelegate = My_InputGetButton;
            KickStarter.playerInput.InputGetButtonDownDelegate = My_InputGetButtonDown;
        }
    
    
        private bool My_InputGetButton (string axisName)
        {
            try
            {
                if (axisName == toggleDragInput)
                {
                    bool isDraggingNow = KickStarter.playerInput.IsDragObjectHeld ();
    
                    if (!isDraggingNow)
                    {
                        if (Input.GetKey (keyCode))
                        {
                            waitForUp = true;
                            return true;
                        }
                        return false;
                    }
                    else
                    {
                        if (waitForUp)
                        {
                            if (!Input.GetKey (keyCode))
                            {
                                waitForUp = false;
                            }
                            return true;
                        }
    
                        if (Input.GetKey (keyCode))
                        {
                            return false;
                        }
                        return true;
                    }
                }
    
                return Input.GetButton (axisName);
            }
            catch {}
    
            return false;
        }
    
    
        private bool My_InputGetButtonDown (string axisName)
        {
            try
            {
                if (axisName == toggleDragInput)
                {
                    return Input.GetKeyDown (keyCode);
                }
    
                return Input.GetButtonDown (axisName);
            }
            catch {}
    
            return false;
        }
    
    }
    
  • Woah thanks, really appreciate going the extra mile.
    So the code gets the key working fine, however as you can see in this video
    https://drive.google.com/open?id=1JWxib7J7YlQGrb1k5KxVd72HiuoXZt-n
    It seems to be simultaneously letting it go and activating it at the same time when you try to untoggle the drag. Only way to untoggle is to move cursor away from the hotspot. For reference, return pick up code is running their, but tried it without it attached too.

  • Remove the Hotspot for the moment, so that we know it's not contributing.

    Try this one, which relies on a defined Unity Input axis, rather than a key set in the Inspector:

    using UnityEngine;
    using AC;
    
    public class ToggleDrag : MonoBehaviour
    {
    
        public string toggleDragInput = "ToggleDrag";
        private bool waitForUp;
        private bool letGoThisFrame;
    
    
        private void Start ()
        {
            KickStarter.playerInput.dragOverrideInput = toggleDragInput;
            KickStarter.playerInput.InputGetButtonDelegate = My_InputGetButton;
        }
    
    
        private void OnEnable ()
        {
            EventManager.OnDropMoveable += OnDropMoveable;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnDropMoveable -= OnDropMoveable;
        }
    
    
        private void OnDropMoveable (DragBase dragBase)
        {
            letGoThisFrame = true;  
        }
    
    
        private void LateUpdate ()
        {
            letGoThisFrame = false;
        }
    
    
        private bool My_InputGetButton (string axisName)
        {
            try
            {
                if (axisName == toggleDragInput)
                {
                    if (letGoThisFrame) return false;
    
                    bool isDraggingNow = KickStarter.playerInput.IsDragObjectHeld ();
    
                    if (!isDraggingNow)
                    {
                        if (Input.GetButton (toggleDragInput))
                        {
                            waitForUp = true;
                            return true;
                        }
                        return false;
                    }
                    else
                    {
                        if (waitForUp)
                        {
                            if (!Input.GetButton (toggleDragInput))
                            {
                                waitForUp = false;
                            }
                            return true;
                        }
    
                        if (Input.GetButton (toggleDragInput))
                        {
                            return false;
                        }
                        return true;
                    }
                }
    
                return Input.GetButton (axisName);
            }
            catch {}
    
            return false;
        }
    
    }
    
  • Unfortunately doesn't work, doing the same thing. I disabled the hotspot as well.

    Looks like when it's in use, and you press the toggle button again, its deactivated and activated at the same time.

  • I'll give it some thought.

  • using UnityEngine;
    using AC;
    
    public class ToggleDrag : MonoBehaviour
    {
    
        public string toggleDragInput = "ToggleDrag";
        private bool waitForUp;
        private bool pressedThisFrame;
    
        private void Start ()
        {
            KickStarter.playerInput.dragOverrideInput = toggleDragInput;
            KickStarter.playerInput.InputGetButtonDelegate = My_InputGetButton;
        }
    
        private void OnEnable ()
        {
            EventManager.OnGrabMoveable += ResetInput;
            EventManager.OnDropMoveable += ResetInput;
        }
    
        private void OnDisable ()
        {
            EventManager.OnGrabMoveable -= ResetInput;
            EventManager.OnDropMoveable -= ResetInput;
        }
    
        private void Update ()
        {
            pressedThisFrame = Input.GetButtonDown (toggleDragInput);
        }
    
        private bool My_InputGetButton (string axisName)
        {
            try
            {
                if (axisName == toggleDragInput)
                {
                    if (!KickStarter.playerInput.IsDragObjectHeld ())
                    {
                        return pressedThisFrame;
                    }
                    else
                    {
                        if (pressedThisFrame)
                        {
                            KickStarter.playerInput.LetGo ();
                            return false;
                        }
                        return true;
                    }
                }
    
                return Input.GetButton (axisName);
            }
            catch {}
    
            return false;
        }
    
        private void ResetInput (DragBase dragBase)
        {
            pressedThisFrame = false;
        }
    
    }
    
  • Works great thank you!

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.