Forum rules - please read before posting.

Puzzle Piece edge scroll with GameCamera2ddrag ?

edited August 20 in Technical Q&A

Hi Chris and fellow AC'ers

Been having a blast setting up an Interactive activity center based on the Puzzle Piece Package.
I'm using the gamecamera2ddrag as my camera so the world can be explored.

I have been trying to get to the following:
When dragging the puzzle piece to the very edge of the screen and keeping it for a little moment, the screen will scroll in the direction of the puzzle piece and stop when the piece is moved away from the edge.

How can I achieve this?

Any direction would be much appreciated,

Best, Dan

Comments

  • edited August 21

    That's a different behaviour to GameCamera2DDrag - which works by dragging the cursor independent of its starting position and without a timer.

    For this behaviour, you'd need a custom script attached to an AC "Basic Camera" component so that it can still be switched to via the Scene Manager and Actions.

    See the Manual's "Custom cameras" chapter for details, but something along these lines may do it:

    using UnityEngine;
    using AC;
    
    public class EdgeScrollCamera : MonoBehaviour
    {
    
        public float scrollSpeed = 10f;
        public float edgeMargin = 0.1f;
        public float scrollDelay = 1f;
        public float minX = -5f;
        public float maxX = 5;
        private float timer;
    
        void Update()
        {
            float mouseX = KickStarter.playerInput.GetMousePosition().x;
            float relativeX = mouseX / ACScreen.width;
            float thisX = transform.position.x;
    
            if (relativeX <= edgeMargin && KickStarter.runtimeInventory.SelectedItem != null)
            {
                timer += Time.deltaTime;
    
                if (timer >= scrollDelay)
                {
                    thisX -= scrollSpeed * Time.deltaTime;
                }
            }
            else if (relativeX >= 1f - edgeMargin && KickStarter.runtimeInventory.SelectedItem != null)
            {
                timer += Time.deltaTime;
    
                if (timer >= scrollDelay)
                {
                    thisX += scrollSpeed * Time.deltaTime;
                }
            }
            else
            {
                timer += Time.deltaTime;
            }
    
            thisX = Mathf.Clamp(thisX, minX, maxX);
            transform.position = new Vector3(thisX, transform.position.y, transform.position.z);
        }
    }
    
  • edited August 22

    I got it to work and now have a screen scrolling whenever the pieces reaches the edges, still respecting the bouncing box and the drag cam.
    Thanks a bunch Chris. Never cease to amaze me how you put into this.
    Been with AC on/off since 2017 and I always find so much joy in playing around with it.
    Thanks!

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.