- Home /
Unable to stop excess input and unable to call the entered combo from the combo system
Hi my name is Tim and I am currently trying to emplace a combo system in my game. However I have encountered a few problems with it, including:
There are excess input of down(S) and right(E) when I pressed the corresponding button, which overflows the combo array I have set;
Sometimes the key presses does not register;
Even if the combo is entered correctly, the combo won't be recognized and show up in the console as activated.
How do I make a combo system which can contain different number of key presses with my combo system? Right now I can only make a combo with 3 presses.
My code for the combo system is here: using UnityEngine; using System.Linq; using System.Collections; using System.Collections.Generic;
[System.Serializable]
public class Combo
{
public string name;
public string[] comboSequence;
}
public class ComboHandler : MonoBehaviour {
public Combo[] combos;
public int comboLimit = 3; // Buffer Size
public int clearBufferTime = 1; //
private string comboActivated;
private List<string> comboToAdd; // Buffer
private float inputBufferTime = 0.1f;
private float bufTime = 0; // Seconds
private float dpadfreezetime = 0.2f;
// Use this for initialization
void Start () {
comboToAdd = new List<string>();
}
// Update is called once per frame
void FixedUpdate () {
float inputX = Input.GetAxis("Horizontal");
float inputY = Input.GetAxis("Vertical");
string direction = "";
if( inputY > 0.2f ) {
direction = "N";
}else if( inputY < -0.2f ) {
direction = "S";
}
if( inputX > 0.2f ) {
direction += "E";
}else if( inputX < -0.2f ) {
direction += "W";
}
// Time span for capturing input key
if(inputBufferTime > 0.1){
if( direction != "" ){
comboToAdd.Add(direction);
print("Key Pressed: "+direction);
}
if( Input.GetButtonDown("Fire") ){
comboToAdd.Add("Fire");
print("Key Pressed: Fire");
}
inputBufferTime = 0;
}else{
inputBufferTime += Time.fixedDeltaTime;
}
// print ("Combo Limit: "+comboLimit);
// print ("Key Count: "+comboToAdd.Count);
if (comboToAdd.Count >= comboLimit)
{
// print (comboToAdd.ToString());
for (int i=0; i<combos.Length; i++)
{
if (comboToAdd.SequenceEqual(combos[i].comboSequence))
{
comboActivated = combos[i].name;
print ("Combo: "+comboActivated);
}
}
comboToAdd.Clear();
}
if( bufTime > clearBufferTime ) {
comboToAdd.Clear();
bufTime = 0;
}
else{
bufTime += Time.fixedDeltaTime;
}
}
}
I would be grateful if anyone can give me advice.
Your answer
![](https://koobas.hobune.stream/wayback/20220613144938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
¿How Can I fill an array in runtime? 3 Answers
Creating a Branching Combo System using a FSM 1 Answer
collision combo 1 Answer
Spell-casting combo system 1 Answer
Play sound from an array, not random, and only once 3 Answers