Reversing Player Controls

To reverse controls drop this code block into whatever class you will have reversing the controls.

make sure you are using InControl; at the top

        private BindingSource[] ActionDownValueP1 = new BindingSource[4];
        private BindingSource[] ActionUpValueP1 = new BindingSource[4];
        private BindingSource[] ActionRightValueP1 = new BindingSource[4];
        private BindingSource[] ActionLeftValueP1 = new BindingSource[4];
        
        private bool HasAlreadyReversedControls = false;
        
        public void ReverseControlsP1(float AmountOfTimeControlsReversed)
        {
            
            GungeonActions actions = BraveInput.PrimaryPlayerInstance.ActiveActions;
            var ActionLeft = actions.Left.Bindings;
            for(int i = 0; i < ActionLeft.Count; i++)
                ActionLeftValueP1[i] = ActionLeft[i];
            var ActionRight = actions.Right.Bindings;
            for (int i = 0; i < ActionRight.Count; i++)
                ActionRightValueP1[i] = ActionRight[i];
            var ActionUp = actions.Up.Bindings;
            for (int i = 0; i < ActionUp.Count; i++)
                ActionUpValueP1[i] = ActionUp[i];
            var ActionDown = actions.Down.Bindings;
            for (int i = 0; i < ActionDown.Count; i++)
                ActionDownValueP1[i] = ActionDown[i];

            actions.Left.ClearBindings();
            actions.Up.ClearBindings();
            actions.Down.ClearBindings();
            actions.Right.ClearBindings();

            for (int i = 0; i < ActionRightValueP1.Length; i++)
                actions.Left.AddBinding(ActionRightValueP1[i]);
            for (int i = 0; i < ActionLeftValueP1.Length; i++)
                actions.Right.AddBinding(ActionLeftValueP1[i]);
            for (int i = 0; i < ActionUpValueP1.Length; i++)
                actions.Down.AddBinding(ActionUpValueP1[i]);
            for (int i = 0; i < ActionDownValueP1.Length; i++)
                actions.Up.AddBinding(ActionDownValueP1[i]);

            HasAlreadyReversedControls = true;
            GameManager.Instance.StartCoroutine(FixControlsP1(AmountOfTimeControlsReversed));
        }

      private IEnumerator FixControlsP1(float SecondsToWait)
        {
            yield return new WaitForSeconds(SecondsToWait);
            GungeonActions actions = BraveInput.PrimaryPlayerInstance.ActiveActions;
            actions.Left.ClearBindings();
            actions.Up.ClearBindings();
            actions.Down.ClearBindings();
            actions.Right.ClearBindings();

            for (int i = 0; i < ActionLeftValueP1.Length; i++)
                actions.Left.AddBinding(ActionLeftValueP1[i]);
            for (int i = 0; i < ActionRightValueP1.Length; i++)
                actions.Right.AddBinding(ActionRightValueP1[i]);
            for (int i = 0; i < ActionDownValueP1.Length; i++)
                actions.Down.AddBinding(ActionDownValueP1[i]);
            for (int i = 0; i < ActionUpValueP1.Length; i++)
                actions.Up.AddBinding(ActionUpValueP1[i]);

            HasAlreadyReversedControls = false;
        }

What this does is grabs the current movement bindings and stores them in fields. It then takes what was up, and uses it for down, takes what was down and uses it for up, etc. Now I hear you say, "BuT An3S, CaNt We JuSt UsE NeGaTiVe MoVeMeNt SpEeD tO rEvErSe CoNtRoLs?" No, you're stupid, and I hate you. Just setting the value to a negative can lead to all sorts of jank and bugs. 1) touching a wall sticks you to that wall and you cant walk off it. 2) trying to enter a boss room soft locks the game. 3) the running dust particles are a never-ending stream. So it is just better to subtly switch the player binds.

Now things will break terribly if you try to reverse controls while they are already reversed, which is why we have the bool HasReversedControls in there. so whenever you call ReverseControls you make sure HasReversedControlls is equal to false. This code can work with player two with some tweaking, but i leave that up to you if you want it. to call it simply go:

if(HasAlreadyReversedControls == false)
    ReverseControlsP1(4);

where 4 is replaced with however many seconds you want controls to be reversed.

Last updated