|
So I'm trying to make my melee attack script so that there are three different attack animations, and if you chain 3 attacks (left mouse clicks) within a certain amount of seconds between each, it will play the different animations for the different attacks. I have it working so that an attackCounter is initialized, and every time the fire button is pressed it is incremented, will play a different animation depending on its value, and reset at 3. Also, every third swing I add another delay(comboDelay) to the delay between swings, so you can only do 3 attacks in a chain before a brief pause. However, I cannot figure out how to make it only increment and play a different animation if the next button press was within the correct timeframe (we'll call it timeAllowedBetweenCombo). Here is the script in its current incarnation:
I've tried adding a variable called lastSwing and setting it equal to Time.time at the end of If(GetButtonDown("Fire1")){, and then checking if Time.time > lastSwing+timeAllowedBetweenCombo inside each of the switch cases, but to no avail :(
(comments are locked)
|
|
What I would do is change the if from Time.time > nextSwing to being within a certain difference from the target time.
So what you could do is put what you have now in that if, but add an }else{ which resets the combo. What is the significance of the Math.Abs part? Also, I can't tell but it seems that in your example, if the swing was not within the time of the last combo swing, there will be no swing at all (rather than resetting and starting over?) I can't really tell, thrown off by the time calculation. Why is time so confusing? :(
Apr 29 '10 at 12:15 AM
PrimeDerektive
(comments are locked)
|
