Forum rules - please read before posting.

Lock cursor not in middle of screen

HI,

Question about locking the cursor -
When locking the cursor, the cursor 'jumps' to the middle of the screen. I find this at times confusing because you may be interacting with a hotspot that is, say, in the right/left of the screen so you expect to continue from where you left before locking the cursor. Is it possible to lock the cursor but leaving it at the position it was on the screen?
Only if the cursor is 'out of bounds' (not on the game screen anymore) put it in the middle.

Many Thanks,

Comments

  • The locked cursor is primarily intended for e.g. first-person games, where the cursor acts like a "centre crosshair". Even while locked, the cursor is still responsive, hence this is the standard position - though you can choose to hide the cursor when it is locked.

    To change the locked position, you need to replace your GameEngine's PlayerInput component with a subclass that overrides the LockedCursorPosition property. Here's an example that should set it to the last unlocked position instead:

    using UnityEngine;
    
    namespace AC
    {
    
        public class Custom_PlayerInput : PlayerInput
        {
    
            private Vector2 unlockedPosition;
            protected override Vector2 LockedCursorPosition
            {
                get
                {
                    return unlockedPosition;
                }
            }
    
            private void Update ()
            {
                if (!cursorIsLocked)
                {
                    unlockedPosition = mousePosition;
                }
            }
    
        }
    
    }
    

    Paste that into a new C# script named Custom_PlayerInput.cs, and replace it with your GameEngine's PlayerInput component.

  • Thank you Chris. The game is indeed first player. I put this script in place of the gameEngine's PlayerInput component but the result is the same. When I lock the cursor (by way of 'ToggleCursor' for instance), the cursor still 'jumps' to the middle of the screen.

  • edited May 20

    It works for me - what are your AC/Unity versions, and did you add it to the GameEngine in the scene, and not the prefab?

    Though, be aware that this will affect the software cursor - not the hardware one. What's your Cursor Manager's "Cursor rendering" field set to?

    When the Hardware (or system) cursor is locked, it is placed in the centre of the screen. This is a product of Unity's behaviour - see this page of their documentation.

    If you're using Software rendering, you can prevent the system cursor from being locked with it by unchecking Lock system cursor when locking AC cursor? in the Cursor Manager.

  • Hi Chris,
    It is now working.
    Unchecking ' Lock system cursor when locking AC cursor?' was the solution.
    Many 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.
Do NOT follow this link or you will be banned from the site!