Forum rules - please read before posting.

Screen Edge Scrolling

Hello.
I'm a beginner in game production. I'm using a translator, so some sentences may not be correct. Sorry.

Is it possible to create a system in which when the cursor is placed on the edge of the screen, the screen scrolls in the direction in which the cursor is placed?
For example, I have a transparent menu at both ends of the screen and imagine the character moving when the cursor is placed on the edge.(first person camera)
Then, when the cursor is shifted from the edge, the character stops moving.
I'd be glad to know a good way to make that happen.

Thank you.

Comments

  • Welcome to the community, @WK_molimoli.

    It can be done with a simple custom script.

    I can assist with this, but I'll need to be clear: you mention use of the first person camera - are you looking to have the character physically move sideways, or just turn the camera, when moving the cursor to the screen's edge?

  • edited December 2024

    Thanks for the reply, Chris.

    I want to physically move the character to the sideways.

  • Thanks for clarifying.

    You can do this by overriding AC's input detection, and have it simulate left/right arrows keys based on the mouse position.

    Copy/paste this code into a C# file named CursorStrafing and attach to a GameObject in the scene, or your Player prefab:

    using UnityEngine;
    using AC;
    
    public class CursorStrafing : MonoBehaviour
    {
    
        [Range (0f, 0.5f)] public float edgeWidth = 0.07f;
    
        void Start ()
        {
            KickStarter.playerInput.InputGetAxisDelegate = MyInputGetAxis;
        }
    
        float MyInputGetAxis (string axisName)
        {
            if (axisName == "Horizontal" && KickStarter.stateHandler.IsInGameplay ())
            {
                // Strafe using cursor position
                float mouseX = KickStarter.playerInput.GetMousePosition ().x;
                float mouseXRelative = mouseX / ACScreen.width;
    
                if (mouseXRelative < edgeWidth)
                {
                    // Strafe left
                    return -1f;
                }
                else if (mouseXRelative > (1f - edgeWidth))
                {
                    // Strafe right
                    return 1f;
                }   
            }
    
            try
            {
                return Input.GetAxis (axisName);
            }
            catch
            {
                return 0f;
            }
        }
    
    }
    
  • I tried it and it worked!
    I am not a programmer but AC makes it very fun to create games.
    Thank you so much!

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.