- Home /
Setting Input windows or queuing user input
Hey guys,
Got another question for you all.
We're coming to the final two weeks of production on our project, "Soulshift" and we've made huge strides here all thanks to you helpful unity members. We're now polishing our game before we present it to the industry professionals that will visit our school on our Industry night and we're now trying to re-visit our combat system and trying to make it more stream-lined.
I was just wondering if there was any way that I could possibly queue user input, as our game is a Hack'n'Slash game. We currently have a 3-hit melee combo and we want to make it so that if user's spam input. They character will do the 3 hit combo, wait slightly and then continue the combo again like normal, if the user continues to spam more input.
Is this difficult to achieve? Because, I've been looking into using the animation window so that I can call animation events in order to set controlled functions within our combat system, but it doesn't seem to be the best way to make it work.
Any and all help would be appreciated! Please help us make this game the best it possibly can be. I'm thinking of making it a downloadable .exe for everyone to download and try once it's complete. We would love to have feedback on what we accomplished and what we can possibly improve upon.
Thanks!
Condor
Answer by Loius · Nov 07, 2012 at 03:28 AM
Definitely possible. Easy to implement as a queueueueue using List -
var queue : List.<String> = new List.<String>();
...
if ( Input.GetButtonDown("Attack") ) {
queue.Add( "Attack" );
}
...
switch case queue[0]:
case "Attack": ContinueCombo();
...
queue.RemoveAt(0); // removes the item at index zero and shifts the rest
Could you explain this is a little more detail? I really appreciate the code snippet!
How can I set it so that it possibly remembers the last 3 times the anims been called?
But don't you already have it doing the 3-hit combo? That's a whole 'nother subject, honestly, but I can try.
You need a concept of "when can the user press a button to continue the combo". While within that time frame, if queue[0] is "attack" and the combo counter is less than three, then continue the combo and increase the combo counter.
You might have something like this:
function Start() { StartCoroutine( AttackListener() ); }
function AttackListener() {
var continueTimes = [ [0.0,$$anonymous$$athf.Infinity], // for step 0 - not attacking - can hit key at any time
[0.5,1.0], // for step 1, must hit key between 0.5 and 1.0 seconds
[0.7,1.1] ];
var comboStep : int = 0;
var currentTime : float;
while ( 1 ) {
currentTime+= Time.deltaTime;
if ( queue.Count > 0 ) {
if ( queue[0]=="Attack" && currentTime > continueTimes[comboStep][0] && currentTime < continueTimes[comboStep][1] ) {
queue.RemoveAt(0);
continue = true;
} else { // they pressed not-attack, so stop the combo
continue = false;
}
if ( continue ) { comboStep++; PlayComboStep(comboStep); }
else { StopComboStep(comboStep); comboStep = 0; }
}
yield;
}
}
This is interesting, I never actually thought about doing it this way. $$anonymous$$y combo script is quite basic compared to this... Haha.
I'm going to try to implement what you wrote here, it's going to take me awhile but this is exactly what I'm looking for. :D
Also, here's my combo script in C# so you have an idea of what we already have in place.
Answer by Condore · Nov 07, 2012 at 07:31 PM
Here's the Combo.CS script.
using UnityEngine;
using System.Collections;
public class Combo : MonoBehaviour
{
public float attack1Time = 1.2f;
public float attack2Time = 1.2f;
public float attack3Time = 1.2f;
float minTimer = 0.6f;
float maxTimer = 0.0f;
public float buffer = 0.4f;
public TP_Animator character;
public ThirdPersonController Controller;
public GameObject currentArmor;
public GameObject whiteArmor;
public GameObject blackArmor;
public katCollision katCollision;
public Collision_clay clayCollision;
int fired = 0;
public AudioSource katanaswing1;
public AudioSource katanaswing2;
public AudioSource katanaswing3;
public AudioSource claymoreswing1;
public AudioSource claymoreswing2;
public AudioSource claymoreswing3;
void Start ()
{
katCollision = GetComponentInChildren<katCollision>();
clayCollision = GetComponentInChildren<Collision_clay>();
Controller = GetComponent<ThirdPersonController>();
character = blackArmor.GetComponent<TP_Animator>();
currentArmor = blackArmor;
}
// Update is called once per frame
void Update ()
{
minTimer -= Time.deltaTime;
maxTimer -= Time.deltaTime;
//reset if player hasn't hit button in time
if (fired >= 1)
{
if (maxTimer < 0)
{
fired = 0;
}
}
if (Input.GetButtonDown ("Fire3"))
{
Controller.isattackingTime = 0.9f;
if(minTimer <= 0)
{
switch (fired) {
case 0:
{
minTimer = attack1Time - buffer;
Debug.Log ("min timer " + minTimer);
maxTimer = attack1Time + buffer;
Debug.Log ("max timer" + maxTimer);
fired = 1;
// Debug.Log("attack 1");
if(currentArmor == blackArmor)
{
katCollision.comboNumber = fired;
character.Attack();
katanaswing1.Play ();
}
if(currentArmor == whiteArmor)
{
clayCollision.comboNumber = fired;
character.AttackClaymore();
claymoreswing1.Play();
}
break;
}
case 1:
{
minTimer = attack2Time - buffer;
Debug.Log ("min timer " + minTimer);
maxTimer = attack2Time + buffer;
Debug.Log ("max timer" + maxTimer);
fired = 2;
// Debug.Log("attack 2");
if(currentArmor == blackArmor)
{
katCollision.comboNumber = fired;
character.Attack1();
katanaswing2.Play ();
}
if(currentArmor == whiteArmor)
{
clayCollision.comboNumber = fired;
character.AttackClaymore1();
claymoreswing3.Play();
}
break;
}
case 2:
{
minTimer = attack3Time - buffer;
Debug.Log ("min timer " + minTimer);
maxTimer = attack3Time + buffer;
Debug.Log ("max timer" + maxTimer);
fired = 3;
//
if(currentArmor == blackArmor)
{
katCollision.comboNumber = fired;
character.Attack2();
katanaswing3.Play ();
}
if(currentArmor == whiteArmor)
{
clayCollision.comboNumber = fired;
character.AttackClaymore2();
claymoreswing3.Play();
}
break;
}
}
}
}
}
}
Your answer
Follow this Question
Related Questions
Melee Combat - Collision Detection 2 Answers
Melee combat, sphereoverlap not working 1 Answer
i need help with my attack point 2 Answers
Localmotion head spinning. 0 Answers
Logic behind multiplayer melee attacks? 0 Answers