Nicel193 / MFPCDocs

0 stars 0 forks source link

Sitting just when key is pressed #2

Closed Johnney1337 closed 7 months ago

Johnney1337 commented 7 months ago

Hey :)

I have a new question. Is it possible to define that sitting should just be hold if the sit key is pressed?

Hopfe for help, thanks! 👍

Nicel193 commented 7 months ago

Hey :)

Yes you can do this, now the sit tracking is done with Action, so I didn't count on such functionality, but it's a little tricky. For the old input system you can write this code.

        public void Update()
        {
            if (UnityEngine.Input.GetKeyDown(KeyCode.Space)) SetJumpInput();
            if (UnityEngine.Input.GetKeyDown(KeyCode.LeftControl)) SetSitInput();
            if (UnityEngine.Input.GetKeyUp(KeyCode.LeftControl)) SetSitInput(); // Cheat;)

            SprintInput();
            MoveInput();
            LookInput();
            LeanInput();
        }

(OldPlayerInputHandler.cs)

For New Input System

        private void Awake()
        {
            _playerInputActions = new PlayerInputActions();
            _playerInputActions.Enable();

            _playerInputActions.Player.Move.SubscribeStartEndAction(OnMove);
            _playerInputActions.Player.Look.SubscribeStartEndAction(OnLook);
            _playerInputActions.Player.Sprint.SubscribeStartEndAction(OnSprint);
            _playerInputActions.Player.Lean.SubscribeStartEndAction(OnLean);
            _playerInputActions.Player.Jump.SubscribeStartAction(OnJump);
            _playerInputActions.Player.Sit.SubscribeStartAction(OnSit);
            _playerInputActions.Player.Sit.SubscribeEndAction(OnSit); // Cheat;)
        }

(NewPlayerInputHandler.cs)

Sorry for the delay(

I hope this helps you.

Nicel193 commented 7 months ago

But it would be better to rewrite sit from Action to bool then it will be more correct. The option I gave is not ideal and some bugs may arise

Johnney1337 commented 7 months ago

That was a good point. I changed it to boolean at it works very well. Thank you :)