[Solved]How to make a sequenced based combo system? Sorta like cheat codes

Background:
I’m trying to make a combat system that uses the a sequence of Xbox controller right analog stick directions input to cast an attack. Example kinda like cheat codes. The user enters a sequence of buttons like X then Y then A and the cheat is enabled. Except for mine I’m using directions Up , then , Down, then Right. and the attack is cast.

Problem:
I figured out how detect Analog stick directions. But i cant make the Combo system

Directional Input Code
Here is my analog stick directional code. It works well but not sure if its how your suppose to do it.
Here i’m just seeing if the player holds the Right Bumper and checks to see if the Analog stick is in the middle of the x and y axis.

        float stickHorzontal = joystickInput.x;
        float stickVertical = joystickInput.y;

    

        if (playerInput.RightBumper == true && stickHorzontal >= .1f && stickVertical >= .1f  )
        {
            print("Upper Right stick pressed");
          
        }
        if (playerInput.RightBumper == true && stickHorzontal >= .5f)
        {
            print("Right stick pressed");
        }

You could make a “queue” for all X actions made by the player. Cherrypick buttons or axis you want for it to detect. Add those as some sort of value to the “queue” when interracted with.

Check that queue if there’s a combo that you want, do an action of it, erase data from queue.

Hey thanks for the reply
I found a combo script but i only works for key codes. Any idea on how to convert if (Input.GetKeyDown(keys[index])) to check for axis press instead?

public class comboSystem : MonoBehaviour {

    public KeyCode[] keys;
    public int index;
    public float inBetweenTime;
    public float lastKeyPressTime;
    public comboSystem(KeyCode[] k)
    {
        index = 0;
        inBetweenTime = 1.5f;
        lastKeyPressTime = 0.0f;
        keys = k;
    }

    public bool check()
    {
        if (Time.time > lastKeyPressTime + inBetweenTime)
        {
            index = 0;
            lastKeyPressTime = Time.time;
            return false;
        }
        else
        {
            if (index < keys.Length)
            {
                if (Input.GetKeyDown(keys[index]))
                {
                    lastKeyPressTime = Time.time;
                    index++;
                    if (index >= keys.Length)
                    {
                        index = 0;
                        return true;
                    }
                    else
                    {
                        return false;
                    }

                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
    }
}

I figured it out :). I shall post my solution to the problem so that future Developers who have the same problem can get the help they need.

How to make a Combo Move Unlock System using the Xbox controller right stick directional axis.

Step 1: create an enum to store joystick input directions

blic enum EJoyStickDirection
    {
        MIDDLE,
        UP,
        UPPERRIGHT,
        RIGHT,
        LOWERIGHT,
        DOWN,
        LOWERLEFT,
        LEFT,
        UPPERLEFT,


    }

    public EJoyStickDirection JoystickState;

Step 2: Create the combo class. Notice the difference between this code and the one i posted above. It takes an enum array instead of a key code. And then checks to see if Joystick state equals keys[index]

  public class ComboTwo
    {

        public EJoyStickDirection[] keys;
        public int index;
        public float inBetweenTime;
        public float lastKeyPressTime;
        [SerializeField]public EJoyStickDirection JoystickState;

        public ComboTwo(EJoyStickDirection[] k)
        {
            index = 0;
            inBetweenTime = 1.5f;
            lastKeyPressTime = 0.0f;
            keys = k;
        }


        public bool check()
        {
            if (Time.time > lastKeyPressTime + inBetweenTime)
            {
                index = 0;
                lastKeyPressTime = Time.time;
                return false;


            }
            else
            {


                if (index < keys.Length)
                {



                    if (JoystickState.Equals(keys[index]))
                    {
                        lastKeyPressTime = Time.time;
                        index++;



                        if (index >= keys.Length)
                        {
                            index = 0;
                            return true;
                        }

                        else
                        {
                            return false;
                        }



                    }



                    else
                    {
                        return false;
                    }





                }




                else
                {
                    return false;
                }
            }
        }


    }

Step 3: Create the object of type Combo

    private ComboTwo combo = new ComboTwo(new EJoyStickDirection[] { EJoyStickDirection.RIGHT , EJoyStickDirection.UPPERRIGHT , EJoyStickDirection.RIGHT});

Step 4: set the track the position of the analog stick. x and y axis. Mine is basic i may come back to refine .

 if (InputController.RightBumper == true && InputController.JoystickInput.x >= .1f && InputController.JoystickInput.y >= .1f)
        {

            combo.JoystickState = EJoyStickDirection.UPPERRIGHT;

        }
        if (InputController.RightBumper == true && InputController.JoystickInput.x >= .5f)
        {
            combo.JoystickState = EJoyStickDirection.RIGHT;

        }

Final step check to see if input matches

 if (combo.check() )
        {
            print("attack 1 has been activated");
        }
1 Like