Forum rules - please read before posting.

Mouse Sensitivity Option to Menu

Hi everyone,

First of all, unfortunately I can't code. I would like to put into Options menu "Mouse sensitivity slider". As I saw it in the forum, it can be solved with coding, but I can't. Little Note: I don't use third party tools. Could somebody helps me with my request?

Thank you:)

Comments

  • I forgot to mention, the movement method is First Person Movement

  • See the Manual's "Remapping inputs" chapter. You can override the InputGetFreeAim delegate with a custom function that takes a Float variable's value into account.

    Create a new Global Variable, make it a float, and link it to Options Data. Create a new Slider in your Options menu, and map it to this variable. This script will then update the sensitivity based on that variable:

    using UnityEngine;
    using AC;
    
    public class MouseSensitivityOption : MonoBehaviour
    {
    
        public int optionID;
    
        private void Start ()
        {
            KickStarter.playerInput.InputGetFreeAimDelegate = CustomGetFreeAim;
        }
    
        public Vector2 CustomGetFreeAim (bool cursorIsLocked = false)
        {
            if (cursorIsLocked)
            {
                GVar variable = GlobalVariables.GetVariable (optionID);
                float scaleFactor = variable.FloatValue;
                return new Vector2 (Input.GetAxis ("CursorHorizontal") * scaleFactor, Input.GetAxis ("CursorVertical") * scaleFactor);
            }
            return Vector2.zero;
        }
    
    }
    

    Place the script in your scene, and be sure to set the "Option ID" Inspector value to match that of your float variable.

  • Thank you very much!

    I did exactly what you wrote, but now, my mouse cursor is got freeze, and I have no free look, so I can't move my mouse and look around in the scene free. If I delete the gameobject what contains this script, everything works perfectly.

    I set the global variable 1 and the OptionID 1 too.

    Any suggestions?

  • What is the variable's value set to in the Variables Manager? If it's zero, you'll get this behaviour.

    This also only works if the AC cursor itself is locked, but this is true of the default behaviour as well.

  • "I set the global variable 1 and the OptionID 1 too." - So it should work, but nothing.

    It's a finished game already, so the FPS movement works.

    I would like to put mouse sensitivity settings only into the menu, but it doesn't works

  • It works for me. What are your AC and Unity versions, and let's see a shot of your Settings Manager.

    Before placing a slider in your options menu, set it's Link to value back to None and play with it's value in the Variables Manager at runtime.

    Try this code to display messages in the Console. What does it show?

    using UnityEngine;
    using AC;
    
    public class MouseSensitivityOption : MonoBehaviour
    {
    
        public int optionID;
    
        private void Start ()
        {
            KickStarter.playerInput.InputGetFreeAimDelegate = CustomGetFreeAim;
        }
    
        public Vector2 CustomGetFreeAim (bool cursorIsLocked = false)
        {
            if (cursorIsLocked)
            {
                GVar variable = GlobalVariables.GetVariable (optionID);
                float scaleFactor = variable.FloatValue;
                Debug.Log ("Cursor unlocked. Free-aim value: " + (new Vector2 (Input.GetAxis ("CursorHorizontal") * scaleFactor, Input.GetAxis ("CursorVertical") * scaleFactor)));
                return new Vector2 (Input.GetAxis ("CursorHorizontal") * scaleFactor, Input.GetAxis ("CursorVertical") * scaleFactor);
            }
            Debug.Log ("Cursor locked.");
            return Vector2.zero;
        }
    
    }
    
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!