Forum rules - please read before posting.

edge scrolling camera 3d

Is it possible to make edge scrolling 3d camera like in fallout1/2 but for 3d games?

Comments

  • edited August 2020

    As in, move the camera once the cursor reaches the screen edge?

    It's not a behaviour provided by any of AC's built-in cameras, but it's fairly simple to incorporate custom camera scripts into AC.

    See the Manual's "Custom cameras" chapter. If you had a script that handled camera movement in the way you wanted, you could then attach the Basic Camera component to it to have it show up in AC Camera fields - e.g. "Default Camera" in the Scene Manager.

    Here's a super-basic example script:

    using UnityEngine;
    using AC;
    
    public class CameraMousePan : MonoBehaviour
    {
    
        public float edgeThreshold = 0.1f;
        public float moveSpeed = 5f;
    
        private Vector3 forwardDirection;
        private Vector3 rightDirection;
    
    
        private void Awake ()
        {
            forwardDirection = new Vector3 (transform.forward.x, 0f, transform.forward.z);
            rightDirection = new Vector3 (transform.right.x, 0f, transform.right.z);
        }
    
    
        private void Update ()
        {
            if (!KickStarter.stateHandler.IsInGameplay ())
            {
                return;
            }
    
            Vector2 relativeMousePosition = new Vector2 (Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height);
    
            if (relativeMousePosition.x < edgeThreshold)
            {
                // Move left
                transform.position -= rightDirection * moveSpeed * Time.deltaTime;
            }
            else if (relativeMousePosition.x > (1f - edgeThreshold))
            {
                // Move right
                transform.position += rightDirection * moveSpeed * Time.deltaTime;
            }
    
            if (relativeMousePosition.y < edgeThreshold)
            {
                // Move up
                transform.position -= forwardDirection * moveSpeed * Time.deltaTime;
            }
            else if (relativeMousePosition.y > (1f - edgeThreshold))
            {
                // Move down
                transform.position += forwardDirection * moveSpeed * Time.deltaTime;
            }
        }
    
    }
    
  • thanks! I will try it

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.